fix(web): isolate subscriber callbacks in pty.onData with try-catch

A throwing callback (e.g. ws.send on a closed socket) would abort the
for-of loop, causing remaining subscribers to miss the data chunk and
skipping the ring buffer update — corrupting replay history for future
reconnections. Wrapping each call in try-catch keeps all subscribers
independent and ensures the buffer update always runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gaurav Bhola 2026-04-02 21:31:20 -07:00
parent 44ff40c0ca
commit faa1bfa8d6
1 changed files with 7 additions and 2 deletions

View File

@ -273,9 +273,14 @@ class TerminalManager {
// Wire up data events
pty.onData((data: string) => {
// Push to all subscribers
// Push to all subscribers — isolate each callback so a throw in one
// (e.g. a closed ws.send) doesn't abort the loop or skip the buffer.
for (const callback of terminal.subscribers) {
callback(data);
try {
callback(data);
} catch (err) {
console.error("[MuxServer] Subscriber callback threw:", err);
}
}
// Append to ring buffer