{"record":{"id":"edde72576dfd6171","repo":"valyala/fasthttp","slug":"unexpected-convert-socket-fd-int-to-uintptr-w","errorCode":null,"errorMessage":"unexpected convert socket fd int to uintptr: %w","messagePattern":"unexpected convert socket fd int to uintptr: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/tcplisten.go","lineNumber":72,"sourceCode":"\tsa, soType, err := getSockaddr(network, addr)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tfd, err := newSocketCloexec(soType, unix.SOCK_STREAM, unix.IPPROTO_TCP)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err = cfg.fdSetup(fd, sa, addr); err != nil {\n\t\tunix.Close(fd)\n\t\treturn nil, err\n\t}\n\n\tfdUintptr, err := safeIntToUintptr(fd)\n\tif err != nil {\n\t\tunix.Close(fd)\n\t\treturn nil, fmt.Errorf(\"unexpected convert socket fd int to uintptr: %w\", err)\n\t}\n\n\tname := fmt.Sprintf(\"reuseport.%d.%s.%s\", os.Getpid(), network, addr)\n\tfile := os.NewFile(fdUintptr, name)\n\tln, err := net.FileListener(file)\n\tif err != nil {\n\t\tfile.Close()\n\t\treturn nil, err\n\t}\n\n\tif err = file.Close(); err != nil {\n\t\tln.Close()\n\t\treturn nil, err\n\t}\n\n\treturn ln, nil\n}\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/tcplisten.go#L54-L90","documentation":"NewListener created a valid socket fd, but the internal safeIntToUintptr(fd) conversion of the descriptor to uintptr failed (the helper rejects values outside the safe non-negative uintptr range). The fd is closed and NewListener returns this error before wrapping it in an *os.File for net.FileListener. In practice this almost always means the fd value was invalid (negative) rather than a genuine overflow.","triggerScenarios":"Any NewListener call where the fd returned by socket creation is negative or otherwise fails the safeIntToUintptr check — i.e. an fd leaked through as negative or an internal invariant violation.","commonSituations":"Corrupted error handling paths where socket creation returned -1 without an error; extreme fd counts theoretically exceeding platform uintptr width on 32-bit systems; custom forks of the library altering fd acquisition.","solutions":["Check that fd limits are sane and the process is not racing with fd closure","Verify you are calling NewListener directly (not passing pre-opened fds) so the library controls fd creation","Report upstream if reproducible — this indicates an internal invariant violation","Update the library version; the safe-conversion helper has been revised across releases"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"ln, err := cfg.NewListener(network, addr)\nif err != nil {\n    if strings.Contains(err.Error(), \"convert socket fd int to uintptr\") {\n        log.Printf(\"internal fd conversion failure; falling back to net.Listen\")\n        ln, err = net.Listen(network, addr) // degrade gracefully\n    }\n}","preventionTips":["Use the library unmodified — this signals an internal invariant violation","Keep library and x/sys versions current","Avoid mixing vendored forks with different fd acquisition logic","Report reproducible cases upstream with the full error chain"],"tags":["network","sockets","internal","fd"],"backgroundTag":"invalid-file-descriptor","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}