Skip to content

Commit fd51195

Browse files
committed
fix log disconnects and remove console logs.
1 parent 30ea3b2 commit fd51195

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

apps/client/src/hooks/useAutomationLogs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const useAutomationLogs = ({
4747
if (level) params.append("level", level)
4848

4949
const url = `${baseUrl}/api/v1/logs/stream?${params.toString()}`
50-
console.log("[useAutomationLogs] Connecting to:", url)
5150

5251
const eventSource = new EventSource(url)
5352

@@ -68,7 +67,6 @@ export const useAutomationLogs = ({
6867
setLogs(historicalLogs)
6968
setIsLoading(false)
7069
} else if (data.type === "log") {
71-
console.log("[useAutomationLogs] New log:", data.log)
7270
// Append new log (not marked as historical)
7371
setLogs((prev) => [...prev, { ...data.log, isHistorical: false }])
7472
}

apps/server/src/app/controllers/app.controller.mts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ export function AppController({
4040
`data: ${JSON.stringify({ type: "initial", logs: existingLogs })}\n\n`,
4141
);
4242

43+
// Send keep-alive heartbeat every 15 seconds to prevent connection timeout
44+
const heartbeatInterval = setInterval(() => {
45+
try {
46+
reply.raw.write(`: heartbeat\n\n`);
47+
} catch (err) {
48+
// Connection closed, cleanup will happen via 'close' event
49+
}
50+
}, 15000);
51+
4352
// Subscribe to new logs
4453
const unsubscribe = code_glue.logger.subscribe(log => {
4554
// Apply filters
@@ -64,13 +73,18 @@ export function AppController({
6473
}
6574

6675
// Send log to client
67-
reply.raw.write(
68-
`data: ${JSON.stringify({ type: "log", log })}\n\n`,
69-
);
76+
try {
77+
reply.raw.write(
78+
`data: ${JSON.stringify({ type: "log", log })}\n\n`,
79+
);
80+
} catch (err) {
81+
// Connection closed, cleanup will happen via 'close' event
82+
}
7083
});
7184

7285
// Cleanup on client disconnect
7386
req.raw.on("close", () => {
87+
clearInterval(heartbeatInterval);
7488
unsubscribe();
7589
});
7690
},

0 commit comments

Comments
 (0)