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

オープン
#519 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@mxpv がすでに取り組んでいます。

2026年11月30日 から。

  • #520 @mxpv による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
43/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
linux, rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
245
フォーク
97
平均マージ
2日 2時間
マージ済み PR(30日)
8

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

containerd/rust-extensions のほかの issue

containerd/rust-extensions の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。