valyala/fasthttp · error
cannot mark listening socket nonblocking: %w
Error message
cannot mark listening socket nonblocking: %w
What it means
On z/OS s390x, socket creation and the FD_CLOEXEC fcntl succeeded, but unix.FcntlInt(fd, F_SETFL, O_NONBLOCK) failed. The library requires a non-blocking listening socket and therefore closes the fd and returns this wrapped error, aborting NewListener.
Source
Thrown at tcplisten/socket_zos_s390x.go:24
"fmt"
"golang.org/x/sys/unix"
)
func newSocketCloexec(domain, typ, proto int) (int, error) {
fd, err := unix.Socket(domain, typ, proto)
if err != nil {
return -1, fmt.Errorf("cannot create listening socket: %w", err)
}
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFD, unix.FD_CLOEXEC)
if err != nil {
unix.Close(fd) //nolint:errcheck
return -1, fmt.Errorf("cannot mark listening socket close-on-exec: %w", err)
}
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFL, unix.O_NONBLOCK)
if err != nil {
unix.Close(fd) //nolint:errcheck
return -1, fmt.Errorf("cannot mark listening socket nonblocking: %w", err)
}
return fd, nil
}
View on GitHub (pinned to c96f600972)
Solutions
- Inspect the wrapped errno to identify EBADF vs EPERM vs EINVAL
- Confirm security software (RACF/ACF2 profiles) permits F_SETFL on socket descriptors
- Raise fd limits and avoid fd exhaustion races
- Pin a newer golang.org/x/sys and Go toolchain with improved z/OS support
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
ln, err := cfg.NewListener("tcp", addr)
if err != nil {
if strings.Contains(err.Error(), "cannot mark listening socket nonblocking") {
var errno syscall.Errno
if errors.As(err, &errno) {
log.Printf("F_SETFL O_NONBLOCK failed: %v — verify security policy permits F_SETFL", errno)
}
return err
}
} Prevention
- Validate sandbox/security policy allows F_SETFL on sockets before rollout
- Keep fd limits generous to avoid transient EBADF
- Pin recent golang.org/x/sys versions with z/OS fixes
- Add a startup health check that opens and closes a non-blocking socket
When it happens
Trigger: Calling NewListener on z/OS s390x when fcntl(F_SETFL, O_NONBLOCK) on the listening socket returns an error (EBADF, EINVAL, or EPERM under restrictive policies).
Common situations: z/OS systems with security software blocking F_SETFL on sockets; rare fd-table races after near-exhaustion; outdated Go z/OS ports with fcntl quirks.
Related errors
- cannot mark listening socket close-on-exec: %w
- cannot create listening socket: %w
- cannot make non-blocked listening socket: %w
- cannot create listening unblocked socket: %w
- unexpected convert socket fd int to uintptr: %w
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/4a62d36355bb5a13.
Report an issue: GitHub.