From 3a2d2f3e8364e1a74dcb4270d901d9889f408f9b 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 54729f2a4c..2635119696 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") }