Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: close http3 server gracefully #6213

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/caddyhttp/app.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 Matthew Holt and The Caddy Authors

Check failure on line 1 in modules/caddyhttp/app.go

View workflow job for this annotation

GitHub Actions / lint (linux)

: # github.com/caddyserver/caddy/v2/modules/caddyhttp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -602,8 +602,7 @@
// 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 {
if err := server.h3server.CloseGracefully(ctx); err != nil {

Check failure on line 605 in modules/caddyhttp/app.go

View workflow job for this annotation

GitHub Actions / lint (linux)

cannot use ctx (variable of type context.Context) as time.Duration value in argument to server.h3server.CloseGracefully

Check failure on line 605 in modules/caddyhttp/app.go

View workflow job for this annotation

GitHub Actions / lint (linux)

cannot use ctx (variable of type context.Context) as time.Duration value in argument to server.h3server.CloseGracefully

Check failure on line 605 in modules/caddyhttp/app.go

View workflow job for this annotation

GitHub Actions / lint (linux)

cannot use ctx (variable of type context.Context) as time.Duration value in argument to server.h3server.CloseGracefully

Check failure on line 605 in modules/caddyhttp/app.go

View workflow job for this annotation

GitHub Actions / govulncheck

cannot use ctx (variable of type context.Context) as time.Duration value in argument to server.h3server.CloseGracefully
app.logger.Error("HTTP/3 server shutdown",
zap.Error(err),
zap.Strings("addresses", server.Listen))
Expand Down
26 changes: 2 additions & 24 deletions modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,31 +568,13 @@
// create HTTP/3 server if not done already
if s.h3server == nil {
s.h3server = &http3.Server{
// Currently when closing a http3.Server, only listeners are closed. But caddy reuses these listeners
// if possible, requests are still read and handled by the old handler. Close these connections manually.
// see issue: https://github.com/caddyserver/caddy/issues/6195
// Will interrupt ongoing requests.
// TODO: remove the handler wrap after http3.Server.CloseGracefully is implemented, see App.Stop
Handler: http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
select {
case <-s.ctx.Done():
if quicConn, ok := request.Context().Value(quicConnCtxKey).(quic.Connection); ok {
//nolint:errcheck
quicConn.CloseWithError(quic.ApplicationErrorCode(http3.ErrCodeRequestRejected), "")
}
default:
s.ServeHTTP(writer, request)
}
}),
Handler: s,
TLSConfig: tlsCfg,
MaxHeaderBytes: s.MaxHeaderBytes,
// TODO: remove this config when draft versions are no longer supported (we have no need to support drafts)
QuicConfig: &quic.Config{
QUICConfig: &quic.Config{

Check failure on line 575 in modules/caddyhttp/server.go

View workflow job for this annotation

GitHub Actions / lint (linux)

unknown field QUICConfig in struct literal of type http3.Server (typecheck)

Check failure on line 575 in modules/caddyhttp/server.go

View workflow job for this annotation

GitHub Actions / lint (linux)

unknown field QUICConfig in struct literal of type http3.Server) (typecheck)

Check failure on line 575 in modules/caddyhttp/server.go

View workflow job for this annotation

GitHub Actions / lint (linux)

unknown field QUICConfig in struct literal of type http3.Server) (typecheck)

Check failure on line 575 in modules/caddyhttp/server.go

View workflow job for this annotation

GitHub Actions / govulncheck

unknown field QUICConfig in struct literal of type http3.Server
Versions: []quic.Version{quic.Version1, quic.Version2},
},
ConnContext: func(ctx context.Context, c quic.Connection) context.Context {
return context.WithValue(ctx, quicConnCtxKey, c)
},
}
}

Expand Down Expand Up @@ -1010,10 +992,6 @@
// For referencing underlying net.Conn
ConnCtxKey caddy.CtxKey = "conn"

// For referencing underlying quic.Connection
// TODO: export if needed later
quicConnCtxKey caddy.CtxKey = "quic_conn"

// For tracking whether the client is a trusted proxy
TrustedProxyVarKey string = "trusted_proxy"

Expand Down