Repository navigation
Prevent terminal query replies from blocking Emacs - #690
Conversation
Use a zero-timeout cancellation token for terminal-generated PTY writes so full child input queues drop replies instead of freezing Emacs.
|
Tested this locally. It fixes the freeze, and I found one residual issue worth a follow-up. SetupBuilt both Wedge detection is an ResultsThe original reproduction from #689 (20,000 DSR queries interleaved with output, child never reads stdin):
The real-world shape that originally hit this —
Under the PR the remote TUI rendered correctly and Emacs stayed responsive throughout. Regression checksBoth pass on the PR, so the zero-timeout give-up does not fire for programs that actually read their input:
One residual: the drop is not all-or-nothing
Repro: fill the queue from a child that is not reading, then drain it and look at what is actually sitting there. import sys, os, re, time, tty
fd = sys.stdin.fileno()
tty.setraw(fd)
w = sys.stdout.write
for _ in range(4000): # stuff the queue while never reading
w('\x1b[6n'); w('z' * 100 + '\r\n')
sys.stdout.flush()
time.sleep(3)
os.set_blocking(fd, False)
buf = b''
end = time.time() + 5
while time.time() < end:
try: buf += os.read(fd, 65536)
except Exception: time.sleep(0.05)
whole = re.findall(rb'\x1b\[\d+;\d+R', buf)
leftover = re.sub(rb'\x1b\[\d+;\d+R', b'', buf)
print('bytes=%d well_formed=%d non_reply_bytes=%d\nleftover=%r'
% (len(buf), len(whole), len(leftover), leftover[:64]))On the PR build: That trailing Suggested narrowing: give up only at None of this is a reason to hold the PR — a mangled escape sequence is a far better failure than a frozen editor. Happy to test a follow-up. |
|
Thanks for testing. On the residual, I would decline the narrowing since that reintroduces the original bug. For a pathological child, this would again make it possible for it to block forever. I will merge this as is. |
Summary
Fixes #689.
Verification
zig build --prefix .zig build test