Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions dashboard/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand Down