valyala/fasthttp · error
cannot disable nagle's algorithm: %w
Error message
cannot disable nagle's algorithm: %w
What it means
fdSetup set TCP_NODELAY on the listening socket (inherited by accepted connections to disable Nagle's algorithm) and setsockopt returned an error. The library treats this as fatal because low-latency behavior is part of its contract; users wanting Nagle can re-enable it later via TCPConn.SetNoDelay(false).
Source
Thrown at tcplisten/tcplisten.go:101
if err = file.Close(); err != nil {
ln.Close()
return nil, err
}
return ln, nil
}
func (cfg *Config) fdSetup(fd int, sa unix.Sockaddr, addr string) error {
var err error
if err = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
return fmt.Errorf("cannot enable so_reuseaddr: %w", err)
}
// This should disable Nagle's algorithm in all accepted sockets by default.
// Users may enable it with net.TCPConn.SetNoDelay(false).
if err = unix.SetsockoptInt(fd, unix.IPPROTO_TCP, unix.TCP_NODELAY, 1); err != nil {
return fmt.Errorf("cannot disable nagle's algorithm: %w", err)
}
if cfg.ReusePort {
if err = unix.SetsockoptInt(fd, unix.SOL_SOCKET, soReusePort, 1); err != nil {
return fmt.Errorf("cannot enable so_reuseport: %w", err)
}
}
if cfg.DeferAccept {
if err = enableDeferAccept(fd); err != nil {
return err
}
}
if cfg.FastOpen {
if err = enableFastOpen(fd); err != nil {
return err
}View on GitHub (pinned to c96f600972)
Solutions
- Check the wrapped errno; ENOPROTOOPT means the platform lacks TCP_NODELAY
- Ensure the network is "tcp"/"tcp4"/"tcp6" so the IPPROTO_TCP option is valid
- Relax sandbox/seccomp restrictions on setsockopt
- Vendor/patch the library to skip TCP_NODELAY if your platform does not support it
Example fix
// before
ln, err := cfg.NewListener("tcp", ":8080")
// after (callers re-enabling Nagle per-connection)
ln, err := cfg.NewListener("tcp", ":8080")
// per conn:
// conn.(*net.TCPConn).SetNoDelay(false) Defensive patterns
Strategy: try-catch
Validate before calling
// verify TCP_NODELAY support before enabling the listener
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
if err == nil {
if serr := syscall.SetsockoptInt(s, syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1); serr != nil {
log.Printf("TCP_NODELAY unsupported here: %v", serr)
}
syscall.Close(s)
} Type guard
null
Try / catch
ln, err := cfg.NewListener("tcp", addr)
if err != nil {
if strings.Contains(err.Error(), "cannot disable nagle") {
var errno syscall.Errno
if errors.As(err, &errno) && errno == syscall.ENOPROTOOPT {
log.Printf("TCP_NODELAY unsupported on this stack; proceeding without")
// vendor a patched fdSetup that tolerates ENOPROTOOPT
}
return err
}
} Prevention
- Only pass "tcp"/"tcp4"/"tcp6" networks to NewListener
- Verify platform support for TCP_NODELAY in CI on the target OS
- Re-enable Nagle per-connection with TCPConn.SetNoDelay(false) instead of patching the library
- Include setsockopt permissions in sandbox/seccomp profiles
When it happens
Trigger: Calling NewListener with network "tcp4"/"tcp6" (IPPROTO_TCP level) where setsockopt(TCP_NODELAY) fails: ENOPROTOOPT (stack lacking the option), EBADF, EPERM in sandboxes.
Common situations: Non-TCP socket families accidentally routed through fdSetup; minimal/exotic TCP stacks (embedded, some BSD variants, older z/OS) lacking TCP_NODELAY; restricted container policies.
Related errors
- fasthttp: dialing to the given tcp address timed out
- couldn't find dns entries for the given domain: try using du
- only tcp, tcp4, or tcp6 is supported
- value is negative, cannot convert to uintptr
- cannot enable so_reuseaddr: %w
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/67c7460673ca3159.
Report an issue: GitHub.