runc-shim: soft RLIMIT_NOFILE stays at the inherited value (e.g. 1024), unlike the Go shim

Open
#519 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mxpv is already working on this.

Since Nov 30, 2026.

  • #520 by @mxpv — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
43/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
linux, rust

Research direction

Start by reading the Rust shim entry point in crates/runc-shim/src/main.rs and compare its startup path with the Go shim’s RLIMIT_NOFILE behavior described in the issue. Check how the project handles Linux resource limits and whether the change belongs in the runc shim or shared crates/shim bootstrap. Done means the Rust shim can handle the reported per-pod file descriptor load and the project’s maintainers have answered whether this limit should be raised in the shim.

Written by the indexing model from the issue text.

Description

Problem

With the Rust runc shim (io.containerd.runc.v2-rs / containerd-shim-runc-v2-rs), the shim process's soft RLIMIT_NOFILE remains at whatever it inherited from containerd (typically 1024 on hosts using the default systemd limits), whereas the Go shim (containerd-shim-runc-v2) ends up with soft ≈ hard (e.g. 524287).

Because the runc v2 shim is pod-level — every container in a pod is served by a single shim process — the shim accumulates per-container file descriptors (stdio FIFOs, log pipes, etc.). With soft=1024 a single pod tops out at roughly ~140 containers, after which starting a new task fails with:

failed to create shim task: ... Too many open files (os error 24)

This is easy to hit on containerd 1.8+/2.x, where the reference containerd.service no longer sets LimitNOFILE (containerd/containerd#8924), so the effective soft limit falls back to systemd's DefaultLimitNOFILE=1024:524288.

Root cause

The Go shim is fine because of the Go runtime, not containerd-specific code:

  • src/syscall/rlimit.go's init() raises the process's own soft NOFILE to hard-1.
  • src/syscall/exec_linux.go restores child processes to the original (pre-raise) limit, so shims start at the inherited 1024 — but the Go shim then re-raises itself via the same init.

The Rust shim has no equivalent: neither crates/shim nor crates/runc-shim calls setrlimit/prlimit, and there is no rlimit dependency. So the Rust shim stays at the inherited 1024.

Measured on the same host, same containerd (2.2.1), same spawn path, only the binary differs:

process soft hard
containerd (Go) 524287 524288
containerd-shim-runc-v2 (Go) 524287 524288
containerd-shim-runc-v2-rs (Rust) 1024 524288

A "fake" shim that just prints its own /proc/self/limits confirms containerd hands the child soft=1024 (Go's exec restores the original rlimit), which the Go shim then re-raises and the Rust shim does not.

Question

Should the Rust shim raise its own soft RLIMIT_NOFILE to the hard limit, mirroring what the Go runtime does for the Go shim? Or is the intended guidance to always configure LimitNOFILE / DefaultLimitNOFILE at the systemd level and leave the shim alone?

I'm happy to send a PR if the maintainers think this belongs in the shim. Two candidate locations:

  1. crates/shim bootstrap — affects every shim built on the framework, and is the closest analog to the Go runtime behavior.
  2. crates/runc-shim/src/main.rs — runc-shim only.

Minimal change (option 2):

#[tokio::main]
async fn main() {
    // Raise soft RLIMIT_NOFILE to the hard limit, mirroring the Go runtime so the
    // pod-level shim can hold per-container FIFO/log fds for many containers.
    #[cfg(target_os = "linux")]
    unsafe {
        let mut rl = libc::rlimit { rlim_cur: 0, rlim_max: 0 };
        if libc::getrlimit(libc::RLIMIT_NOFILE, &mut rl) == 0 {
            rl.rlim_cur = rl.rlim_max;
            let _ = libc::setrlimit(libc::RLIMIT_NOFILE, &rl);
        }
    }
    parse_version();
    run::<Service>("io.containerd.runc.v2-rs", None).await;
}

Happy to adjust to the project's preferred location / style.

Dominant language
Rust
Stars
245
Forks
97
Avg merge
2d 2h
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from containerd/rust-extensions

All issues in containerd/rust-extensions

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.