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

Đang mở
#519 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mxpv đang làm issue này rồi.

Từ ngày 30/11/2026.

  • #520 của @mxpv — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
linux, rust
Lĩnh vực
backend, operating-systems

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
245
Fork
97
Merge trung bình
2 ngày 2 giờ
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của containerd/rust-extensions

Tất cả issue của containerd/rust-extensions

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.