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

  1. Inspect the wrapped errno to identify EBADF vs EPERM vs EINVAL
  2. Confirm security software (RACF/ACF2 profiles) permits F_SETFL on socket descriptors
  3. Raise fd limits and avoid fd exhaustion races
  4. 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

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


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/4a62d36355bb5a13. Report an issue: GitHub.