From c9b5e7f77b8aac7334d81c552c583af81ba1c400 Mon Sep 17 00:00:00 2001 From: Artem Mikheev <30644072+renbou@users.noreply.github.com> Date: Wed, 23 Mar 2022 02:47:57 +0300 Subject: Fix http3 servers dying after reload (#4654) --- modules/caddyhttp/app.go | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'modules/caddyhttp') diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go index 64cc540..d81f556 100644 --- a/modules/caddyhttp/app.go +++ b/modules/caddyhttp/app.go @@ -18,7 +18,6 @@ import ( "context" "crypto/tls" "fmt" - "net" "net/http" "strconv" "time" @@ -116,9 +115,8 @@ type App struct { // affect functionality. Servers map[string]*Server `json:"servers,omitempty"` - servers []*http.Server - h3servers []*http3.Server - h3listeners []net.PacketConn + servers []*http.Server + h3servers []*http3.Server ctx caddy.Context logger *zap.Logger @@ -353,9 +351,9 @@ func (app *App) Start() error { app.logger.Info("enabling experimental HTTP/3 listener", zap.String("addr", hostport), ) - h3ln, err := caddy.ListenPacket("udp", hostport) + h3ln, err := caddy.ListenQUIC(hostport, tlsCfg) if err != nil { - return fmt.Errorf("getting HTTP/3 UDP listener: %v", err) + return fmt.Errorf("getting HTTP/3 QUIC listener: %v", err) } h3srv := &http3.Server{ Server: &http.Server{ @@ -366,9 +364,8 @@ func (app *App) Start() error { }, } //nolint:errcheck - go h3srv.Serve(h3ln) + go h3srv.ServeListener(h3ln) app.h3servers = append(app.h3servers, h3srv) - app.h3listeners = append(app.h3listeners, h3ln) srv.h3server = h3srv } ///////// @@ -426,13 +423,6 @@ func (app *App) Stop() error { } } - // close the http3 servers; it's unclear whether the bug reported in - // https://github.com/caddyserver/caddy/pull/2727#issuecomment-526856566 - // was ever truly fixed, since it seemed racey/nondeterministic; but - // recent tests in 2020 were unable to replicate the issue again after - // repeated attempts (the bug manifested after a config reload; i.e. - // reusing a http3 server or listener was problematic), but it seems - // to be working fine now for _, s := range app.h3servers { // TODO: CloseGracefully, once implemented upstream // (see https://github.com/lucas-clemente/quic-go/issues/2103) @@ -441,17 +431,6 @@ func (app *App) Stop() error { return err } } - - // closing an http3.Server does not close their underlying listeners - // since apparently the listener can be used both by servers and - // clients at the same time; so we need to manually call Close() - // on the underlying h3 listeners (see lucas-clemente/quic-go#2103) - for _, pc := range app.h3listeners { - err := pc.Close() - if err != nil { - return err - } - } return nil } -- cgit v1.2.3