From 03baf16f7eeb533551cbbed32bd0b521a44d1593 Mon Sep 17 00:00:00 2001 From: Oliver Baer <75138893+mrwind-up-bird@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:18:32 +0100 Subject: [PATCH] fix(autofix): Unhandled promise rejection in stream processing --- dashboard/js/api.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/dashboard/js/api.js b/dashboard/js/api.js index 940974b..6b158c2 100644 --- a/dashboard/js/api.js +++ b/dashboard/js/api.js @@ -168,7 +168,21 @@ const API = { method: 'POST', headers, body: JSON.stringify(body), - }); + // Ensure reader is properly closed on any exit path + const cleanup = () => { + reader.releaseLock(); + }; + + let readResult; + try { + readResult = await reader.read(); + } catch (readErr) { + cleanup(); + onError?.(readErr.message || 'Stream read error'); + return; + } + + const { done, value } = readResult; } catch (err) { onError?.(err.message || 'Network error'); return; @@ -186,6 +200,11 @@ const API = { onError?.(data.detail || `HTTP ${resp.status}`); return; } + } catch (parseErr) { + // Log parse error but continue processing other events + console.warn('Failed to parse SSE data:', dataStr, parseErr); + continue; + } const reader = resp.body.getReader(); const decoder = new TextDecoder(); @@ -205,9 +224,9 @@ const API = { for (const part of parts) { if (!part.trim()) continue; - let eventType = 'message'; - let dataStr = ''; - + cleanup(); + cleanup(); + return; for (const line of part.split('\n')) { if (line.startsWith('event: ')) { eventType = line.slice(7);