From a2c82a73d9bcaf932d775cd0561bb5b6b8bec07f Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Tue, 20 Mar 2018 14:41:22 +0000 Subject: [PATCH] Make upstream.Close() wait for shutdown We let main() exit, and block on graceful shutdown in a `defer`ed procedure. We _also_ `defer` a call to `upstream.Close()`, which stops the upstream reconnecting and closes it. The two deferred procedure calls used to be in such an order that by coincidence, `upstream.Close()` was _also_ blocked on graceful shutdown. But this order was shuffled in PR #962. This commit makes the `upstream.Close()` explicitly wait for shutdown. --- cmd/fluxd/main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 54729f2a4..263511969 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -398,7 +398,10 @@ func main() { os.Exit(1) } daemon.EventWriter = upstream - defer upstream.Close() + go func() { + <-shutdown + upstream.Close() + }() } else { logger.Log("upstream", "no upstream URL given") }