mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-18 16:55:37 +03:00
caddyhttp: Fix h3 shutdown (#5541)
* swap h3server close and listener close, avoid quic-listener not closing * fix typo
This commit is contained in:
parent
bd34cb6b4e
commit
29452647d8
2 changed files with 16 additions and 8 deletions
|
@ -594,6 +594,21 @@ func (app *App) Stop() error {
|
||||||
return
|
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
|
// TODO: we have to manually close our listeners because quic-go won't
|
||||||
// close listeners it didn't create along with the server itself...
|
// close listeners it didn't create along with the server itself...
|
||||||
// see https://github.com/quic-go/quic-go/issues/3560
|
// 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()))
|
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) {
|
stopH2Listener := func(server *Server) {
|
||||||
defer finishedShutdown.Done()
|
defer finishedShutdown.Done()
|
||||||
|
|
|
@ -555,7 +555,7 @@ func (s *Server) serveHTTP3(addr caddy.NetworkAddress, tlsCfg *tls.Config) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.h3listeners = append(s.h3listeners, lnAny.(net.PacketConn))
|
s.h3listeners = append(s.h3listeners, ln)
|
||||||
|
|
||||||
//nolint:errcheck
|
//nolint:errcheck
|
||||||
go s.h3server.ServeListener(h3ln)
|
go s.h3server.ServeListener(h3ln)
|
||||||
|
|
Loading…
Reference in a new issue