diff options
author | WeidiDeng <[email protected]> | 2023-05-20 00:00:00 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2023-05-19 10:00:00 -0600 |
commit | 29452647d803aa1259b4430b52349ce7ac1495a4 (patch) | |
tree | 240dbd873c657d1abbd4e3a4b0b9438df4eafc91 /modules/caddyhttp/app.go | |
parent | bd34cb6b4e171567243ff541ca303ac32fec91d8 (diff) | |
download | caddy-29452647d803aa1259b4430b52349ce7ac1495a4.tar.gz caddy-29452647d803aa1259b4430b52349ce7ac1495a4.zip |
caddyhttp: Fix h3 shutdown (#5541)
* swap h3server close and listener close, avoid quic-listener not closing
* fix typo
Diffstat (limited to 'modules/caddyhttp/app.go')
-rw-r--r-- | modules/caddyhttp/app.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go index 0e02afdd3..f774c3ae4 100644 --- a/modules/caddyhttp/app.go +++ b/modules/caddyhttp/app.go @@ -594,6 +594,21 @@ func (app *App) Stop() error { return } + // First close h3server then close listeners unlike stdlib for several reasons: + // 1, udp has only a single socket, once closed, no more data can be read and + // written. In contrast, closing tcp listeners won't affect established connections. + // This have something to do with graceful shutdown when upstream implements it. + // 2, h3server will only close listeners it's registered (quic listeners). Closing + // listener first and these listeners maybe unregistered thus won't be closed. caddy + // distinguishes quic-listener and underlying datagram sockets. + + // TODO: CloseGracefully, once implemented upstream (see https://github.com/quic-go/quic-go/issues/2103) + if err := server.h3server.Close(); err != nil { + app.logger.Error("HTTP/3 server shutdown", + zap.Error(err), + zap.Strings("addresses", server.Listen)) + } + // TODO: we have to manually close our listeners because quic-go won't // close listeners it didn't create along with the server itself... // see https://github.com/quic-go/quic-go/issues/3560 @@ -604,13 +619,6 @@ func (app *App) Stop() error { zap.String("address", el.LocalAddr().String())) } } - - // TODO: CloseGracefully, once implemented upstream (see https://github.com/quic-go/quic-go/issues/2103) - if err := server.h3server.Close(); err != nil { - app.logger.Error("HTTP/3 server shutdown", - zap.Error(err), - zap.Strings("addresses", server.Listen)) - } } stopH2Listener := func(server *Server) { defer finishedShutdown.Done() |