ipfs/kubo · error
invalid rlimits
Error message
invalid rlimits
What it means
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.
Source
Thrown at cmd/ipfs/util/ulimit_freebsd.go:23
import (
"errors"
"math"
unix "golang.org/x/sys/unix"
)
func init() {
supportsFDManagement = true
getLimit = freebsdGetLimit
setLimit = freebsdSetLimit
}
func freebsdGetLimit() (uint64, uint64, error) {
rlimit := unix.Rlimit{}
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)
if (rlimit.Cur < 0) || (rlimit.Max < 0) {
return 0, 0, errors.New("invalid rlimits")
}
return uint64(rlimit.Cur), uint64(rlimit.Max), err
}
func freebsdSetLimit(soft uint64, max uint64) error {
if (soft > math.MaxInt64) || (max > math.MaxInt64) {
return errors.New("invalid rlimits")
}
rlimit := unix.Rlimit{
Cur: int64(soft),
Max: int64(max),
}
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
}
View on GitHub (pinned to 329838acdf)
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.
Example fix
// before ipfs daemon # inside a jail with unlimited nofile (Cur/Max = -1) // after # in jail.conf: # rlimit; or set explicit: exec.prestart + limits -n 8192 limits -n 8192 && ipfs daemon
Defensive patterns
Strategy: type-guard
Validate before calling
var r unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &r); err != nil { return err }
if r.Cur < 0 || r.Max < 0 {
return fmt.Errorf("kernel reported invalid rlimits: cur=%d max=%d", r.Cur, r.Max)
} Type guard
func validRlimit(r unix.Rlimit) bool { return r.Cur >= 0 && r.Max >= 0 } Try / catch
changed, newLimit, err := util.ManageFdLimit()
if err != nil && err.Error() == "invalid rlimits" {
return fmt.Errorf("freebsd rlimits unusable in this jail/environment: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error setting ulimit without hard limit: %w
- failed to raise ulimit to IPFS_FD_MAX (%d): set to %d
- failed to raise ulimit to minimum %d: set to %d
- error setting: ulimit: %w
- assets: could load Asset '%s': %s
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/d5150a74a45ced0c.
Report an issue: GitHub.