Attaching from a zero-size terminal panics

未关闭
#445 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
6

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

shell-pool/shpool 的其他 Issue

查看 shell-pool/shpool 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。