Files
tty7/src
l0ng-aiandl0ng-ai 692cb76635 fix(windows): never join the pane reader on the UI thread (#407)
* fix(windows): never join the pane reader on the UI thread

On Windows, shutdown() does not wake a thread parked in a blocking
read() on the same socket (it does on unix). detach_link, adopt_relink,
and Drop all shut the writer down and then joined the reader thread,
counting on that wake-up - so when the peer stayed silent (a routed
pane whose SSH leg went zombie: nothing arrives, no FIN ever comes),
the join blocked its caller, the UI thread. That is the whole-window
'not responding' hang right after a remote workspace reconnects.

Teardown now sets a per-reader quit flag and abandons the thread
instead of joining it. The reader's read always times out within
500 ms so a parked reader notices the flag promptly, and it re-checks
the flag under the term lock before every grid mutation, so a retired
reader can never touch the freshly reset grid of an adopted link.

The new windows-only tests fail on the old code by blocking >3 s in
detach_link; the reader teardown previously had no Windows coverage
at all (the whole test module is cfg(unix)).

* fix(windows): gate every buffered frame on the reader's quit flag

Review follow-up on #407: the quit checks guarded the grid and the
exited flag, but a retired reader could still hold complete frames in
its local buffer and process them — and most arms (Cwd, Prompt, Agent,
and especially Exited via child_exited) write shared state that
adopt_relink reuses across the swap, so a buffered Exited from the
abandoned link could close the freshly adopted pane. Check the flag
once per frame at the top of the inner loop, so a retired reader
processes nothing at all; the adopt test now also fires a late Exited
down the abandoned link and asserts the pane survives.

---------

Co-authored-by: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
2026-08-08 14:39:38 +08:00
..