{"record":{"id":"d5150a74a45ced0c","repo":"ipfs/kubo","slug":"invalid-rlimits","errorCode":null,"errorMessage":"invalid rlimits","messagePattern":"invalid rlimits","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/ipfs/util/ulimit_freebsd.go","lineNumber":23,"sourceCode":"\nimport (\n\t\"errors\"\n\t\"math\"\n\n\tunix \"golang.org/x/sys/unix\"\n)\n\nfunc init() {\n\tsupportsFDManagement = true\n\tgetLimit = freebsdGetLimit\n\tsetLimit = freebsdSetLimit\n}\n\nfunc freebsdGetLimit() (uint64, uint64, error) {\n\trlimit := unix.Rlimit{}\n\terr := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)\n\tif (rlimit.Cur < 0) || (rlimit.Max < 0) {\n\t\treturn 0, 0, errors.New(\"invalid rlimits\")\n\t}\n\treturn uint64(rlimit.Cur), uint64(rlimit.Max), err\n}\n\nfunc freebsdSetLimit(soft uint64, max uint64) error {\n\tif (soft > math.MaxInt64) || (max > math.MaxInt64) {\n\t\treturn errors.New(\"invalid rlimits\")\n\t}\n\trlimit := unix.Rlimit{\n\t\tCur: int64(soft),\n\t\tMax: int64(max),\n\t}\n\treturn unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)\n}\n","sourceCodeStart":5,"sourceCodeEnd":38,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/cmd/ipfs/util/ulimit_freebsd.go#L5-L38","documentation":"freebsdGetLimit reads the process RLIMIT_NOFILE via unix.Getrlimit and returns this error when either the current (soft) or max (hard) rlimit value is negative. On FreeBSD rlimit fields are signed, and a negative value means the kernel returned an unusable/corrupt limit, so the caller refuses to proceed rather than compute on a bogus value.","triggerScenarios":"Calling ManageFdLimit() on FreeBSD when unix.Getrlimit(RLIMIT_NOFILE) returns rlimit.Cur < 0 or rlimit.Max < 0. Note the function still also returns the Getrlimit error if one occurred, but the sentinel fires purely on negative fields.","commonSituations":"Jails or sandboxed FreeBSD environments reporting odd rlimit values; platform-specific signed/unsigned mismatches when the rlimit is effectively unlimited (RLIM_INFINITY); running kubo on unusual FreeBSD derivatives.","solutions":["Inspect the actual rlimit with `limits -n` inside the jail/environment and correct it in the jail.conf rlimit settings.","Verify kernel/platform sanity; if RLIM_INFINITY is represented as -1 and trips this check, run the daemon with a finite nofile limit instead of unlimited.","Upgrade kubo/boxo to a version with current FreeBSD rlimit handling, and report the issue with the output of `uname -a` and `limits` if it persists."],"exampleFix":"// before\nipfs daemon   # inside a jail with unlimited nofile (Cur/Max = -1)\n// after\n# in jail.conf:\n#   rlimit;   or set explicit: exec.prestart + limits -n 8192\nlimits -n 8192 && ipfs daemon","handlingStrategy":"type-guard","validationCode":"var r unix.Rlimit\nif err := unix.Getrlimit(unix.RLIMIT_NOFILE, &r); err != nil { return err }\nif r.Cur < 0 || r.Max < 0 {\n    return fmt.Errorf(\"kernel reported invalid rlimits: cur=%d max=%d\", r.Cur, r.Max)\n}","typeGuard":"func validRlimit(r unix.Rlimit) bool { return r.Cur >= 0 && r.Max >= 0 }","tryCatchPattern":"changed, newLimit, err := util.ManageFdLimit()\nif err != nil && err.Error() == \"invalid rlimits\" {\n    return fmt.Errorf(\"freebsd rlimits unusable in this jail/environment: %w\", err)\n}","preventionTips":["Inside FreeBSD jails, set finite nofile rlimits (jail.conf rlimit or `limits -n`) instead of unlimited, since -1 trips the validation","Run a preflight Getrlimit check on FreeBSD before starting the daemon","Keep kubo updated on FreeBSD so platform-specific rlimit handling fixes are picked up"],"tags":["freebsd","ulimit","rlimit","go"],"backgroundTag":"invalid-rlimit-value","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"}