From df5627ab196235cefc559b9c397fe4aa27e48923 Mon Sep 17 00:00:00 2001 From: renovate <renovate-bot@autistici.org> Date: Fri, 26 May 2023 13:32:59 +0000 Subject: [PATCH] Update git.autistici.org/ai3/go-common digest to 5afdaf0 --- go.mod | 2 +- go.sum | 2 + .../ai3/go-common/serverutil/http.go | 75 +++++++++++++++---- .../ai3/go-common/serverutil/tls.go | 1 + vendor/modules.txt | 2 +- 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 3713a15..6060e8d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.autistici.org/id/usermetadb go 1.14 require ( - git.autistici.org/ai3/go-common v0.0.0-20221125154433-06304016b1da + git.autistici.org/ai3/go-common v0.0.0-20230526131513-5afdaf014661 github.com/google/go-cmp v0.5.9 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect diff --git a/go.sum b/go.sum index baa1d03..78d5269 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,8 @@ git.autistici.org/ai3/go-common v0.0.0-20221125135645-b1672785dfec h1:LUpRIeP9IE git.autistici.org/ai3/go-common v0.0.0-20221125135645-b1672785dfec/go.mod h1:FTGqOGPpuoFg7TiHshYCyp5j1Ab3ek0J0KcS++vEjxw= git.autistici.org/ai3/go-common v0.0.0-20221125154433-06304016b1da h1:fizdAjFv2vWz+83IoeRW2L0Shyo3dDquXyQKWRGs4jc= git.autistici.org/ai3/go-common v0.0.0-20221125154433-06304016b1da/go.mod h1:FTGqOGPpuoFg7TiHshYCyp5j1Ab3ek0J0KcS++vEjxw= +git.autistici.org/ai3/go-common v0.0.0-20230526131513-5afdaf014661 h1:QidAfAxaIMWWu52luWF30wvRpv7t+Ic73xxsTUENqSU= +git.autistici.org/ai3/go-common v0.0.0-20230526131513-5afdaf014661/go.mod h1:FTGqOGPpuoFg7TiHshYCyp5j1Ab3ek0J0KcS++vEjxw= github.com/Azure/azure-amqp-common-go/v2 v2.1.0/go.mod h1:R8rea+gJRuJR6QxTir/XuEd+YuKoUiazDC/N96FiDEU= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-sdk-for-go v29.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= diff --git a/vendor/git.autistici.org/ai3/go-common/serverutil/http.go b/vendor/git.autistici.org/ai3/go-common/serverutil/http.go index b257535..ebfe6b6 100644 --- a/vendor/git.autistici.org/ai3/go-common/serverutil/http.go +++ b/vendor/git.autistici.org/ai3/go-common/serverutil/http.go @@ -104,13 +104,20 @@ func (config *ServerConfig) buildHTTPHandler(h http.Handler) (http.Handler, *tls return h, tlsConfig, nil } -// Serve HTTP(S) content on the specified address. If config.TLS is -// not nil, enable HTTPS and TLS authentication. -// -// This function will return an error if there are problems creating -// the listener, otherwise it will handle graceful termination on -// SIGINT or SIGTERM and return nil. -func Serve(h http.Handler, config *ServerConfig, addr string) error { +func buildListener(addr string, tlsConfig *tls.Config) (net.Listener, error) { + // Create the net.Listener first, so we can detect + // initialization-time errors safely. + l, err := net.Listen("tcp", addr) + if err != nil { + return nil, err + } + if tlsConfig != nil { + l = tls.NewListener(l, tlsConfig) + } + return l, nil +} + +func buildServer(h http.Handler, config *ServerConfig, addr string) (*http.Server, error) { // Wrap with tracing handler (exclude metrics and other // debugging endpoints). h = tracing.WrapHandler(h, guessEndpointName(addr)) @@ -118,7 +125,7 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { // Create the top-level HTTP handler with all our additions. hh, tlsConfig, err := config.buildHTTPHandler(h) if err != nil { - return err + return nil, err } // These are not meant to be external-facing servers, so we @@ -131,14 +138,24 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { TLSConfig: tlsConfig, } - // Create the net.Listener first, so we can detect - // initialization-time errors safely. - l, err := net.Listen("tcp", addr) + return srv, nil +} + +// Serve HTTP(S) content on the specified address. If config.TLS is +// not nil, enable HTTPS and TLS authentication. +// +// This function will return an error if there are problems creating +// the listener, otherwise it will handle graceful termination on +// SIGINT or SIGTERM and return nil. +func Serve(h http.Handler, config *ServerConfig, addr string) error { + srv, err := buildServer(h, config, addr) if err != nil { return err } - if srv.TLSConfig != nil { - l = tls.NewListener(l, srv.TLSConfig) + + l, err := buildListener(addr, srv.TLSConfig) + if err != nil { + return err } // Install a signal handler for gentle process termination. @@ -176,6 +193,38 @@ func Serve(h http.Handler, config *ServerConfig, addr string) error { return nil } +// ServeWithContext operates like Serve but with a controlling Context +// that can be used to stop the HTTP server. +func ServeWithContext(ctx context.Context, h http.Handler, config *ServerConfig, addr string) error { + srv, err := buildServer(h, config, addr) + if err != nil { + return err + } + + l, err := buildListener(addr, srv.TLSConfig) + if err != nil { + return err + } + + go func() { + <-ctx.Done() + + sctx, cancel := context.WithTimeout(context.Background(), gracefulShutdownTimeout) + srv.Shutdown(sctx) // nolint: errcheck + srv.Close() + cancel() + }() + + daemon.SdNotify(false, "READY=1") // nolint + + err = srv.Serve(l) + if err == http.ErrServerClosed { + err = nil + } + + return err +} + func addDefaultHandlers(h http.Handler) http.Handler { root := http.NewServeMux() diff --git a/vendor/git.autistici.org/ai3/go-common/serverutil/tls.go b/vendor/git.autistici.org/ai3/go-common/serverutil/tls.go index 21c002b..b81b047 100644 --- a/vendor/git.autistici.org/ai3/go-common/serverutil/tls.go +++ b/vendor/git.autistici.org/ai3/go-common/serverutil/tls.go @@ -123,6 +123,7 @@ func (c *TLSServerConfig) TLSConfig() (*tls.Config, error) { CipherSuites: serverCiphers, MinVersion: tls.VersionTLS12, PreferServerCipherSuites: true, + NextProtos: []string{"h2", "http/1.1"}, } // Require client certificates if a CA is specified. diff --git a/vendor/modules.txt b/vendor/modules.txt index 03f5119..2ad72dd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# git.autistici.org/ai3/go-common v0.0.0-20221125154433-06304016b1da +# git.autistici.org/ai3/go-common v0.0.0-20230526131513-5afdaf014661 ## explicit git.autistici.org/ai3/go-common git.autistici.org/ai3/go-common/clientutil -- GitLab