mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-23 00:56:45 +01:00
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.
This commit is contained in:
parent
6115a462c7
commit
6f01928512
1 changed files with 4 additions and 0 deletions
4
caddy.go
4
caddy.go
|
@ -888,6 +888,10 @@ func Stop() error {
|
|||
}
|
||||
inst := instances[0]
|
||||
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 {
|
||||
log.Printf("[ERROR] Stopping %s: %v", inst.serverType, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue