Client ID reuse after output backpressure causes stale plugin UI and lets an old disconnect evict a new attach
Description
In Zellij 0.45.0, when a client stops consuming server output and its
5000-message ClientSender queue becomes full, the server removes that client
from ServerOsInputOutput and SessionState, but does not synchronously remove
it from Screen or WasmBridge.
SessionState::new_client() immediately reuses the lowest free numeric client
ID. A new attach can therefore receive the same ID while the old route thread
and old per-client plugin/Grid state still exist.
This causes two observable problems:
- The first new attach reuses stale tab-bar/status-bar WASM and
PluginPaneGrid state. The bar can initially contain only background-colored blank cells. Resizing may only replay the old Grid. - When the old route thread eventually emits
RemoveClient(id), it removes the newly attached client that now owns the same numeric ID. The new client exits withBye from Zellij!.
A second attach often looks correct because it receives another client ID and
changes TabUpdate.other_focused_clients, forcing the built-in bars to render.
Environment
- Zellij 0.45.0
- macOS Terminal.app -> SSH -> Linux server
- Also reproduced locally on Linux with a clean
/dev/nullconfiguration - Latest main at
035876d7af8dc20465190b4923a3282690ddb2abstill has the same lifecycle
Reproduction
The following uses util-linux script to create a client whose terminal output
is not consumed:
session="zellij-client-id-reuse-repro"
zellij --config /dev/null attach --create-background "$session"
setsid sh -c "(sleep 300) | script -qefc \
'stty rows 54 cols 213; TERM=xterm-256color exec zellij attach $session' \
/dev/null | (sleep 300)" >/dev/null 2>&1 &
slow_group_pid=$!
zellij --session "$session" run -- \
bash -lc 'timeout 120 yes abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'Wait until the log contains:
client 1 is processing server messages too slow
sending on a full channelAttach from a second terminal:
TERM=xterm-256color zellij attach "$session"Then terminate only the original blocked attach from the first terminal:
kill -- "-$slow_group_pid"The new attach is disconnected at the same time and prints Bye from Zellij!.
Controlled reproduction evidence
- Slow client started at
01:28:56 client 1 is processing server messages too slowat01:29:53- New attach started at
01:30:29while the old attach process still existed - Both attach processes existed, but the server only had tab-bar/status-bar instances for client ID 1; no client ID 2 instance was created
- Terminating the old attach caused both the old and new attach processes to exit
- The sender thread logged exactly 4,999
Broken pipeerrors
Relevant source paths
- The client queue is bounded to 5000 in
zellij-server/src/os_input_output.rs. - The
send_to_client!failure path removes the client from transport andSessionState, but does not sendScreenInstruction::RemoveClientorPluginInstruction::RemoveClient. SessionState::new_client()reuses the lowest free numeric ID.ServerInstruction::RemoveClienthas no connection generation/token.WasmBridge::add_client()skips an existing(plugin_id, client_id)instance.WasmBridge::remove_client()does not remove the per-client WASM instance.PluginPaneretains per-client Grid/parser/frame maps.
Expected behavior
A stale disconnect must never remove a newer connection that reused the same numeric client ID. A fresh attach should receive a fully regenerated plugin UI.
Suggested fix direction
- Add a connection generation/token and require it for all removal operations, or prevent reuse until the old connection has fully terminated.
- Route backpressure disconnects through one canonical, idempotent cleanup path
that updates
SessionState,ScreenandWasmBridge. - Reset or remove per-client WASM/Grid state on disconnect or fresh attach.
- Stop draining and logging every queued message after the socket has failed.
Possibly related: #5372.
Source: zellij-org/zellij