#5546·zellij

Client ID reuse after output backpressure causes stale plugin UI and lets an old disconnect evict a new attach

Author: qiuyuhangCreated Aug 26, 2026Updated Sep 30, 2026
Labelssuspected bug

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:

  1. The first new attach reuses stale tab-bar/status-bar WASM and PluginPane Grid state. The bar can initially contain only background-colored blank cells. Resizing may only replay the old Grid.
  2. 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 with Bye 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/null configuration
  • Latest main at 035876d7af8dc20465190b4923a3282690ddb2ab still has the same lifecycle

Reproduction

The following uses util-linux script to create a client whose terminal output is not consumed:

bash
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 channel

Attach from a second terminal:

bash
TERM=xterm-256color zellij attach "$session"

Then terminate only the original blocked attach from the first terminal:

bash
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 slow at 01:29:53
  • New attach started at 01:30:29 while 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 pipe errors

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 and SessionState, but does not send ScreenInstruction::RemoveClient or PluginInstruction::RemoveClient.
  • SessionState::new_client() reuses the lowest free numeric ID.
  • ServerInstruction::RemoveClient has 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.
  • PluginPane retains 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, Screen and WasmBridge.
  • 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.