Attaching from a zero-size terminal panics

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

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

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

評価

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

調査の方向性

Start with the reproduction script in the issue, run it against a local build, and read the panic sites: screen.rs:897 (Screen::text) and grid.rs:200 (Screen::el) in the vendored shpool_vt100 crate. The attach path is spawn_shell_to_client and handle_attach in libshpool's daemon shell module, which is where the zero-size resize is passed to the parser. Done means a 0x0 attach or create no longer kills the shell-to-client thread, and later attaches succeed in all three session_restore_mode cases.

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

説明

vterm

AI Policy Ack
ACK

This bug report is written manually.
However, I used an AI agent to investigate the issue and create a reproduction script.

What happened

  • My bash startup attaches to shpool from every interactive bash, potentially reusing disconnected sessions.
  • Since May, my terminals regularly couldn't attach.
  • My suspicion was that this was somehow related to VSCode's WSL connections.
  • I also saw resized fd (rows=0, cols=0) entries just before panics that tried to unwrap a None value at shpool_vt100-0.1.3/src/screen.rs:897.
  • My daemon logged this 67 times between May and October.
  • It happens with session_restore_mode set to { lines = 1000 } (mine) or "screen", but not with "simple".

What I expected to happen

  • The attach should either work or be refused before creating a session.

To Reproduce

Here is an agent-created script that reproduces the issue by either creating a new session from a zero-size terminal (case A) or reattaching from a zero-size terminal (case B)

#!/usr/bin/env bash
# Reproduces a shpool panic: an attach from a terminal of size 0x0 kills
# the session's shell->client thread, and the session can never be
# attached again. Case A creates a new session at 0x0; case B reattaches
# a disconnected one at 0x0. Runs its own daemon on its own socket in a
# temporary directory, so no running shpool is touched. Needs util-linux's
# `script`.
#
#   usage: SHPOOL=/path/to/shpool shpool-zero-size.sh [lines|screen|simple]
set -u
shpool=${SHPOOL:-shpool}
mode=${1:-lines}
dir=$(mktemp -d)
sock=$dir/shpool.socket
log=$dir/daemon.log

case $mode in
  lines) restore='session_restore_mode = { lines = 1000 }' ;;
  screen) restore='session_restore_mode = "screen"' ;;
  simple) restore='session_restore_mode = "simple"' ;;
  *) echo "unknown mode $mode" >&2; exit 2 ;;
esac
cat >"$dir/config.toml" <<EOF
shell = "/bin/sh"
norc = true
prompt_prefix = ""
$restore
EOF
attach="$shpool -c $dir/config.toml -s $sock attach"

# Attach $2 from a terminal of size $1, for at most 3 seconds; exit 124
# means it was still attached when timeout ended it, as it should be.
try() {
  script -qec "stty $1; timeout 3 $attach $2" /dev/null >/dev/null
  echo "$?"
}
status() { "$shpool" -s "$sock" list | grep "^$1"; }

echo "shpool: $("$shpool" version), session_restore_mode: $mode"
RUST_BACKTRACE=1 "$shpool" -c "$dir/config.toml" -s "$sock" -l "$log" daemon 2>"$dir/daemon.stderr" &
daemon=$!
trap 'kill "$daemon" 2>/dev/null; wait "$daemon" 2>/dev/null' EXIT
for _ in $(seq 50); do [[ -S $sock ]] && break; sleep 0.1; done

echo "A. a new session from a 0x0 terminal"
echo "   create at 0x0 exited $(try 'rows 0 cols 0' fresh)"
sleep 2
echo "   attach at 24x80 exited $(try 'rows 24 cols 80' fresh)"
echo "   attach -f at 24x80 exited $(try 'rows 24 cols 80' '-f fresh')"
echo "   list: $(status fresh)"

echo "B. a disconnected session reattached from a 0x0 terminal"
echo "   create at 24x80 exited $(try 'rows 24 cols 80' old)"
for _ in $(seq 50); do status old | grep -q disconnected && break; sleep 0.1; done
echo "   reattach at 0x0 exited $(try 'rows 0 cols 0' old)"
sleep 2
echo "   reattach at 24x80 exited $(try 'rows 24 cols 80' old)"
echo "   reattach -f at 24x80 exited $(try 'rows 24 cols 80' '-f old')"
echo "   list: $(status old)"

echo "--- daemon stderr, the panics:"
grep -a -E "panicked at|^ +[0-9]+: " "$dir/daemon.stderr"
echo "--- daemon log, the attaches after them:"
grep -a -E "clobbering|joining shell->client on reattach|error shuffling" "$log" | sed 's/^[^ ]* *//'
echo "(full log: $log)"

Output:

shpool: shpool 0.11.0, session_restore_mode: lines
A. a new session from a 0x0 terminal
   create at 0x0 exited 1
   attach at 24x80 exited 124
   attach -f at 24x80 exited 1
   list: fresh  disconnected
B. a disconnected session reattached from a 0x0 terminal
   create at 24x80 exited 124
   reattach at 0x0 exited 1
   reattach at 24x80 exited 124
   reattach -f at 24x80 exited 1
   list: old    disconnected
--- daemon stderr, the panics:
thread 'shell->client(fresh)' (665098) panicked at /build/shpool-0.11.0-vendor/source-registry-0/shpool_vt100-0.1.3/src/screen.rs:897:18:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <shpool_vt100::screen::Screen>::text
   5: <shpool_vt100::parser::Parser>::process
   6: <libshpool::daemon::shell::SessionInner>::spawn_shell_to_client::{closure#0}
thread 'shell->client(old)' (665178) panicked at /build/shpool-0.11.0-vendor/source-registry-0/shpool_vt100-0.1.3/src/grid.rs:200:14:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <shpool_vt100::screen::Screen>::el
   5: <vte::Parser<1024>>::action_csi_dispatch::<shpool_vt100::perform::WrappedScreen>
   6: <shpool_vt100::parser::Parser>::process
   7: <libshpool::daemon::shell::SessionInner>::spawn_shell_to_client::{closure#0}
--- daemon log, the attaches after them:
WARN ThreadId(17) handle_conn{cid=6}:handle_attach:select_shell_lock_1(shells):aquired_lock(session.inner){s="fresh"}: child_exited chan unclosed, but shell->client thread has exited, clobbering with new subshell
ERROR ThreadId(17) handling new connection: joining shell->client on reattach: Any { .. }
ERROR ThreadId(20) handle_conn{cid=9}:handle_attach: error shuffling bytes: attaching new client stream to shell->client thread
WARN ThreadId(47) handle_conn{cid=28}:handle_attach:select_shell_lock_1(shells):aquired_lock(session.inner){s="old"}: child_exited chan unclosed, but shell->client thread has exited, clobbering with new subshell
ERROR ThreadId(47) handling new connection: joining shell->client on reattach: Any { .. }
ERROR ThreadId(50) handle_conn{cid=31}:handle_attach: error shuffling bytes: attaching new client stream to shell->client thread
(full log: /tmp/tmp.xI41MzDEcq/daemon.log)

Version info

shpool 0.11.0

Logs

Full logs for the reproduction script: daemon.log

主要言語
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 を短くまとめたダイジェスト。