diff --git a/app.go b/app.go index 3305f9b5..49006ec0 100644 --- a/app.go +++ b/app.go @@ -479,15 +479,15 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error { } // Update fiber server settings app.init() + // Start prefork + if app.Settings.Prefork { + return app.prefork(addr, tlsconfig...) + } // Set correct network protocol network := "tcp4" if isIPv6(addr) { network = "tcp6" } - // Start prefork - if app.Settings.Prefork { - return app.prefork(network, addr, tlsconfig...) - } // Setup listener ln, err := net.Listen(network, addr) if err != nil { diff --git a/prefork.go b/prefork.go index 055f4df6..beb50f37 100644 --- a/prefork.go +++ b/prefork.go @@ -29,12 +29,17 @@ func (app *App) IsChild() bool { } // prefork manages child processes to make use of the OS REUSEPORT or REUSEADDR feature -func (app *App) prefork(network, addr string, tlsconfig ...*tls.Config) (err error) { +func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) { // 👶 child process 👶 if app.IsChild() { // use 1 cpu core per child process runtime.GOMAXPROCS(1) var ln net.Listener + // Set correct network protocol + network := "tcp4" + if isIPv6(addr) { + network = "tcp6" + } // 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 {