Attaching from a zero-size terminal panics

Abierto
#445 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
2k
Forks
70
Merge medio
2 d 3 h
PR fusionados (30 d)
6

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de shell-pool/shpool

Todos los issues de shell-pool/shpool

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.