{"record":{"id":"c3ad8b5bc406d308","repo":"ipfs/kubo","slug":"error-setting-ulimit-w","errorCode":null,"errorMessage":"error setting: ulimit: %w","messagePattern":"error setting: ulimit: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/ipfs/util/ulimit.go","lineNumber":110,"sourceCode":"\t\tif newLimit < userLimit {\n\t\t\terr = fmt.Errorf(\n\t\t\t\t\"failed to raise ulimit to IPFS_FD_MAX (%d): set to %d\",\n\t\t\t\tuserLimit,\n\t\t\t\tnewLimit,\n\t\t\t)\n\t\t\tbreak\n\t\t}\n\n\t\tif userLimit == 0 && newLimit < minFds {\n\t\t\terr = fmt.Errorf(\n\t\t\t\t\"failed to raise ulimit to minimum %d: set to %d\",\n\t\t\t\tminFds,\n\t\t\t\tnewLimit,\n\t\t\t)\n\t\t\tbreak\n\t\t}\n\tdefault:\n\t\terr = fmt.Errorf(\"error setting: ulimit: %w\", err)\n\t}\n\n\treturn newLimit > 0, newLimit, err\n}\n","sourceCodeStart":92,"sourceCodeEnd":115,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/cmd/ipfs/util/ulimit.go#L92-L115","documentation":"The default branch of ManageFdLimit's error switch: setLimit returned an error other than nil or syscall.EPERM while raising the file-descriptor limit. The error only appears on platforms where supportsFDManagement is true; on Linux an error in the same path is returned unwrapped earlier, so this branch primarily covers platforms whose setLimit returns arbitrary syscall errors.","triggerScenarios":"ManageFdLimit() where setLimit(targetLimit, targetLimit) returns any non-nil, non-EPERM error, e.g. EINVAL from an invalid rlimit value or EPERM surfaced as a wrapped error rather than the bare syscall value.","commonSituations":"Exotic or restricted kernels/sandboxes rejecting setrlimit; values above the kernel's fs.nr_open on Linux-like builds; a wrapped EPERM that fails the errors.Is-style switch, sending an ordinary permission failure into the default branch.","solutions":["Inspect the wrapped error with errors.Is/As (e.g. syscall.EINVAL) to determine the OS-level cause.","Check that IPFS_FD_MAX is a sane number below fs.nr_open (`sysctl fs.nr_open`).","Verify the platform actually supports FD management (supportsFDManagement) and that the failure is not a sandbox/seccomp policy blocking setrlimit."],"exampleFix":"// before\nerr = fmt.Errorf(\"error setting: ulimit: %w\", err) // opaque errno\n// after (caller diagnosis)\nvar errno syscall.Errno\nif errors.As(err, &errno) {\n    log.Warnf(\"setrlimit failed: %v\", errno)\n}","handlingStrategy":"try-catch","validationCode":"// pre-check the value about to be set\nwant := uint64(8192)\nif v := os.Getenv(\"IPFS_FD_MAX\"); v != \"\" {\n    w, err := strconv.ParseUint(v, 10, 64)\n    if err != nil || w == 0 || w > 1<<40 {\n        log.Warnf(\"invalid IPFS_FD_MAX %q\", v)\n    }\n}","typeGuard":"func isErrno(err error) (syscall.Errno, bool) {\n    var e syscall.Errno\n    if errors.As(err, &e) { return e, true }\n    return 0, false\n}","tryCatchPattern":"changed, newLimit, err := util.ManageFdLimit()\nif err != nil {\n    var errno syscall.Errno\n    if errors.As(err, &errno) {\n        switch errno {\n        case syscall.EINVAL:\n            log.Warnf(\"setrlimit EINVAL: value above fs.nr_open? err=%v\", err)\n        default:\n            log.Warnf(\"setrlimit failed (%v), continuing\", err)\n        }\n    }\n}","preventionTips":["Keep IPFS_FD_MAX below the kernel fs.nr_open ceiling on Linux-like platforms","Treat errors from ManageFdLimit as advisory (match on wrapped errno) since a non-EPERM errno may be environmental","Log the wrapped cause rather than the outer message when triaging; the errno is the actionable part"],"tags":["ulimit","syscall","file-descriptors","go"],"backgroundTag":"setrlimit-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}