Attaching from a zero-size terminal panics

Đang mở
#445 1 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

Chưa có ai nhận issue này.

Đá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
30/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

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.

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

Mô tả

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

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

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

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 shell-pool/shpool

Tất cả issue của shell-pool/shpool

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.