Session becomes unattachable after shell->client poll() returns EINTR

オープン 初心者向け
#442 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend

調査の方向性

libshpool/src/daemon/shell.rs と shell_inject.rs にある2つの poll ループを読みます。issue では、541〜547行付近の shell ループがリンクされています。各ループが poll エラーをどのように処理するかを確認し、EINTR を再現するか、このケースをカバーするテストを追加してください。完了条件は、両方のループが EINTR の場合に再試行し、再現手順に記載されたシグナルの後もセッションに接続できることです。

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

説明

What happens

When several sessions share one daemon, a session can break permanently: every later shpool attach <name> for it exits with status 1, and the daemon logs

ERROR handle_conn{cid=..}:handle_attach: error shuffling bytes: attaching new client stream to shell->client thread

The session stays listed (disconnected/attached) but can never be attached again; only shpool kill recovers it.

Cause

The session's shell->client thread had exited earlier, at the moment another session in the same daemon spawned its shell:

INFO  handle_conn{cid=18}:handle_attach:spawn_subshell: about to fork subshell noecho=false
ERROR shell->client{s="main" cid=3}: polling pty master: EINTR

poll(2) returns EINTR whenever a signal is delivered to the polling thread, and that is never restarted, whatever SA_RESTART says. The shell->client loop treats it as fatal:

https://github.com/shell-pool/shpool/blob/3c41df9a610428b6c1766d78d36d3fefd5685c3b/libshpool/src/daemon/shell.rs#L541-L547

So any signal the kernel happens to deliver to that thread (for example the SIGCHLD when another session's shell starts or exits) ends the thread and leaves the session unattachable. The sentinel poll in shell_inject.rs has the same pattern.

Suggested fix

Retry on EINTR in both poll loops, e.g. Err(nix::errno::Errno::EINTR) => continue,, or block the relevant signals on these threads.

Reproduction

shpool 0.11.5 (shpool-x86_64-unknown-linux-gnu release binary), Ubuntu 24.04 container:

  1. Attach to session a and leave it running a command that prints continuously.
  2. In the same daemon, repeatedly create sessions, run exit in them, and force-reattach a (we drove ~20 sessions through ttyd).
  3. It is a race, so it does not happen every round; we hit it twice. When a's shell->client thread logs polling pty master: EINTR, every later attach to a fails as above.

We hit it on an x86_64 container under Docker Desktop on Apple silicon (Rosetta), which may deliver signals to that thread more often, but the code path is the same on native Linux.

Workaround

One daemon per session (shpool --socket <per-session path> attach <name>), so no other session's children signal that daemon. With that, the same stress run passed repeatedly.

主要言語
Rust
スター
2k
フォーク
70
平均マージ
2日 3時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

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

shell-pool/shpool のほかの issue

shell-pool/shpool の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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