diff --git a/cmd/start/start.go b/cmd/start/start.go index 4ae1e15b08..a191998e1e 100644 --- a/cmd/start/start.go +++ b/cmd/start/start.go @@ -6,7 +6,6 @@ import ( _ "embed" "fmt" "math" - "net" "net/http" "os" "os/signal" @@ -22,7 +21,6 @@ import ( "github.com/zitadel/saml/pkg/provider" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" - "golang.org/x/sys/unix" "github.com/zitadel/zitadel/cmd/key" cmd_tls "github.com/zitadel/zitadel/cmd/tls" @@ -392,20 +390,11 @@ func startAPIs( return nil } -func reusePort(network, address string, conn syscall.RawConn) error { - return conn.Control(func(descriptor uintptr) { - err := syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) - if err != nil { - panic(err) - } - }) -} - func listen(ctx context.Context, router *mux.Router, port uint16, tlsConfig *tls.Config, shutdown <-chan os.Signal) error { http2Server := &http2.Server{} http1Server := &http.Server{Handler: h2c.NewHandler(router, http2Server), TLSConfig: tlsConfig} - lc := &net.ListenConfig{Control: reusePort} + lc := listenConfig() lis, err := lc.Listen(ctx, "tcp", fmt.Sprintf(":%d", port)) if err != nil { return fmt.Errorf("tcp listener on %d failed: %w", port, err) diff --git a/cmd/start/start_port.go b/cmd/start/start_port.go new file mode 100644 index 0000000000..bb60fea250 --- /dev/null +++ b/cmd/start/start_port.go @@ -0,0 +1,11 @@ +//go:build !integration + +package start + +import ( + "net" +) + +func listenConfig() *net.ListenConfig { + return &net.ListenConfig{} +} diff --git a/cmd/start/start_port_integration.go b/cmd/start/start_port_integration.go new file mode 100644 index 0000000000..1c5763d6e9 --- /dev/null +++ b/cmd/start/start_port_integration.go @@ -0,0 +1,25 @@ +//go:build integration + +package start + +import ( + "net" + "syscall" + + "golang.org/x/sys/unix" +) + +func listenConfig() *net.ListenConfig { + return &net.ListenConfig{ + Control: reusePort, + } +} + +func reusePort(network, address string, conn syscall.RawConn) error { + return conn.Control(func(descriptor uintptr) { + err := syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) + if err != nil { + panic(err) + } + }) +}