Commit 6f019285 authored by Damir Vandic's avatar Damir Vandic Committed by Matt Holt

Fix graceful shutdown (#2618)

Currently, the instance waitgroup is decremented twice in `startServers()`: once when `Serve()` is finished and once when `ServePacket()` is finished. However, with a graceful shutdown, `Serve()` returns before the server has actually finished shutting down all active connections. This patch increases the wait group by one when the server is shut down so that the program only exits when all the server instances have finished serving their connections.
parent 6115a462
...@@ -888,6 +888,10 @@ func Stop() error { ...@@ -888,6 +888,10 @@ func Stop() error {
} }
inst := instances[0] inst := instances[0]
instancesMu.Unlock() instancesMu.Unlock()
// Increase the instance waitgroup so that the last wait() call in
// caddymain/run.go blocks until this server instance has shut down
inst.wg.Add(1)
defer inst.wg.Done()
if err := inst.Stop(); err != nil { if err := inst.Stop(); err != nil {
log.Printf("[ERROR] Stopping %s: %v", inst.serverType, err) log.Printf("[ERROR] Stopping %s: %v", inst.serverType, err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment