From faa1bfa8d6473e74c0b1bb349136caa32949bcdc Mon Sep 17 00:00:00 2001 From: Gaurav Bhola Date: Thu, 2 Apr 2026 21:31:20 -0700 Subject: [PATCH] fix(web): isolate subscriber callbacks in pty.onData with try-catch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/web/server/mux-websocket.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/web/server/mux-websocket.ts b/packages/web/server/mux-websocket.ts index 220c6b9ed..16bdb1003 100644 --- a/packages/web/server/mux-websocket.ts +++ b/packages/web/server/mux-websocket.ts @@ -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