{"record":{"id":"4a62d36355bb5a13","repo":"valyala/fasthttp","slug":"cannot-mark-listening-socket-nonblocking-w","errorCode":null,"errorMessage":"cannot mark listening socket nonblocking: %w","messagePattern":"cannot mark listening socket nonblocking: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/socket_zos_s390x.go","lineNumber":24,"sourceCode":"\t\"fmt\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc newSocketCloexec(domain, typ, proto int) (int, error) {\n\tfd, err := unix.Socket(domain, typ, proto)\n\tif err != nil {\n\t\treturn -1, fmt.Errorf(\"cannot create listening socket: %w\", err)\n\t}\n\t_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFD, unix.FD_CLOEXEC)\n\tif err != nil {\n\t\tunix.Close(fd) //nolint:errcheck\n\t\treturn -1, fmt.Errorf(\"cannot mark listening socket close-on-exec: %w\", err)\n\t}\n\t_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFL, unix.O_NONBLOCK)\n\tif err != nil {\n\t\tunix.Close(fd) //nolint:errcheck\n\t\treturn -1, fmt.Errorf(\"cannot mark listening socket nonblocking: %w\", err)\n\t}\n\treturn fd, nil\n}\n","sourceCodeStart":6,"sourceCodeEnd":28,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/socket_zos_s390x.go#L6-L28","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"ln, err := cfg.NewListener(\"tcp\", addr)\nif err != nil {\n    if strings.Contains(err.Error(), \"cannot mark listening socket nonblocking\") {\n        var errno syscall.Errno\n        if errors.As(err, &errno) {\n            log.Printf(\"F_SETFL O_NONBLOCK failed: %v — verify security policy permits F_SETFL\", errno)\n        }\n        return err\n    }\n}","preventionTips":["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"],"tags":["network","sockets","zos","s390x","nonblocking","fcntl"],"backgroundTag":"socket-nonblock-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}