From 7f44f5b017c22d132a10ff20339a2792a27da38d Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Sat, 18 Jul 2020 01:19:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20detect=20tcp=20proto=20by=20addr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 8 ++++---- prefork.go | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) 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 {