{"record":{"id":"8c95273ab445db2b","repo":"valyala/fasthttp","slug":"cannot-enable-so-reuseport-w","errorCode":null,"errorMessage":"cannot enable so_reuseport: %w","messagePattern":"cannot enable so_reuseport: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/tcplisten.go","lineNumber":106,"sourceCode":"\treturn ln, nil\n}\n\nfunc (cfg *Config) fdSetup(fd int, sa unix.Sockaddr, addr string) error {\n\tvar err error\n\n\tif err = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {\n\t\treturn fmt.Errorf(\"cannot enable so_reuseaddr: %w\", err)\n\t}\n\n\t// This should disable Nagle's algorithm in all accepted sockets by default.\n\t// Users may enable it with net.TCPConn.SetNoDelay(false).\n\tif err = unix.SetsockoptInt(fd, unix.IPPROTO_TCP, unix.TCP_NODELAY, 1); err != nil {\n\t\treturn fmt.Errorf(\"cannot disable nagle's algorithm: %w\", err)\n\t}\n\n\tif cfg.ReusePort {\n\t\tif err = unix.SetsockoptInt(fd, unix.SOL_SOCKET, soReusePort, 1); err != nil {\n\t\t\treturn fmt.Errorf(\"cannot enable so_reuseport: %w\", err)\n\t\t}\n\t}\n\n\tif cfg.DeferAccept {\n\t\tif err = enableDeferAccept(fd); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif cfg.FastOpen {\n\t\tif err = enableFastOpen(fd); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif err = unix.Bind(fd, sa); err != nil {\n\t\treturn fmt.Errorf(\"cannot bind to %q: %w\", addr, err)\n\t}","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/tcplisten.go#L88-L124","documentation":"When the Config has ReusePort enabled, fdSetup sets SO_REUSEPORT (or SO_REUSEPORT_LB on FreeBSD/Darwin via soReusePort) and this setsockopt failed. ReusePort is opt-in, so this error only occurs when the user explicitly requested it and the platform/kernel cannot honor the option.","triggerScenarios":"Calling tcplisten.Config{ReusePort: true}.NewListener(...) on platforms/kernels without SO_REUSEPORT support (older Linux <3.9 without the patch defining soReusePort appropriately, or Windows), or when setsockopt returns EPERM/EINVAL/ENOPROTOOPT.","commonSituations":"Enabling ReusePort on unsupported kernels or platforms (Windows, very old Linux); containers stripping the option; mismatched constant selection per GOOS; permission restrictions on the socket.","solutions":["Disable ReusePort (tcplisten.Config{ReusePort: false}) if the kernel does not support it","Run Linux >= 3.9 (or FreeBSD with SO_REUSEPORT_LB >= FreeBSD 12) for SO_REUSEPORT support","Check the wrapped errno; EPERM suggests sandbox restrictions, ENOPROTOOPT an unsupported option","Gate ReusePort at startup with a runtime capability check before calling NewListener"],"exampleFix":"// before\ncfg := tcplisten.Config{ReusePort: true}\nln, err := cfg.NewListener(\"tcp\", \":8080\") // fails on unsupported kernel\n// after\ncfg := tcplisten.Config{ReusePort: reusePortSupported()} // runtime-detected\nln, err := cfg.NewListener(\"tcp\", \":8080\")","handlingStrategy":"fallback","validationCode":"// runtime capability probe for SO_REUSEPORT\nfunc reusePortSupported() bool {\n    s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, 0)\n    if err != nil { return false }\n    defer syscall.Close(s)\n    return syscall.SetsockoptInt(s, syscall.SOL_SOCKET, soReusePortConst, 1) == nil\n}","typeGuard":"null","tryCatchPattern":"cfg := tcplisten.Config{ReusePort: true}\nln, err := cfg.NewListener(\"tcp\", addr)\nif err != nil && strings.Contains(err.Error(), \"cannot enable so_reuseport\") {\n    cfg.ReusePort = false // graceful degradation\n    ln, err = cfg.NewListener(\"tcp\", addr)\n}","preventionTips":["Probe SO_REUSEPORT support at startup and degrade to ReusePort=false","Require Linux >= 3.9 (or FreeBSD 12+ for SO_REUSEPORT_LB) in deployment docs","Don't enable ReusePort on Windows/unsupported platforms","Document kernel requirements alongside the zero-downtime restart setup"],"tags":["network","sockets","reuseport","setsockopt","kernel"],"backgroundTag":"reuseport-unsupported","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}