summaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-05-12 11:36:20 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-05-12 11:36:20 -0600
commitaef560c7fc52092a412d9e97112b8cb879c5eda5 (patch)
tree905fce22478842dd8a8d07a65c8769e7db1c4cad /admin.go
parent44536a7594f060dfca54a3cfb36135c93cba8e59 (diff)
all: Recover from panics in goroutines
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/admin.go b/admin.go
index 6831686..1d19066 100644
--- a/admin.go
+++ b/admin.go
@@ -520,16 +520,19 @@ func handleStop(w http.ResponseWriter, r *http.Request) error {
if err != nil {
Log().Named("admin.api").Error("unload error", zap.Error(err))
}
- go func() {
- err := stopAdminServer(adminServer)
- var exitCode int
- if err != nil {
- exitCode = ExitCodeFailedQuit
- Log().Named("admin.api").Error("failed to stop admin server gracefully", zap.Error(err))
- }
- Log().Named("admin.api").Info("stopping now, bye!! 👋")
- os.Exit(exitCode)
- }()
+ if adminServer != nil {
+ // use goroutine so that we can finish responding to API request
+ go func() {
+ err := stopAdminServer(adminServer)
+ var exitCode int
+ if err != nil {
+ exitCode = ExitCodeFailedQuit
+ Log().Named("admin.api").Error("failed to stop admin server gracefully", zap.Error(err))
+ }
+ Log().Named("admin.api").Info("stopping now, bye!! 👋")
+ os.Exit(exitCode)
+ }()
+ }
return nil
}