diff --git a/app.go b/app.go index 3b76ec68..d41b0b0d 100644 --- a/app.go +++ b/app.go @@ -490,9 +490,6 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error { app.init() // Start prefork if app.Settings.Prefork { - if app.Settings.Network == "tcp6" || isIPv6(addr) { - return fmt.Errorf("listen: tcp6 is not supported when prefork is enabled") - } return app.prefork(addr, tlsconfig...) } // Setup listener diff --git a/prefork.go b/prefork.go index 5a62a006..e955a110 100644 --- a/prefork.go +++ b/prefork.go @@ -35,8 +35,13 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) { // use 1 cpu core per child process runtime.GOMAXPROCS(1) var ln net.Listener - // SO_REUSEPORT is not supported on Windows, use SO_REUSEADDR instead - if ln, err = reuseport.Listen("tcp4", addr); err != nil { + network := "tcp4" + if app.Settings.Network == "tcp6" { + network = app.Settings.Network + } + // Linux will use SO_REUSEPORT and Windows falls back to SO_REUSEADDR + // Only tcp4 or tcp6 is supported when preforking, both are not supported + if ln, err = reuseport.Listen(network, addr); err != nil { if !app.Settings.DisableStartupMessage { time.Sleep(100 * time.Millisecond) // avoid colliding with startup message }