Skip to content

Commit

Permalink
fix(core, ui): send a "start" event to be sure the UI receive the SSE
Browse files Browse the repository at this point in the history
The UI only store a reference to the logs SSE when receive the first event.
In case a flow didn't emit any log, or the logs tab is closed before any logs is emitted, the UI will not have any reference to the SSE so the SSE connection would stay alive forever.
Each SSE connection starts a thread via the logs queue, creating a thread leak.

Sending a first "start" event makes sure the UI has a reference to the SSE.
  • Loading branch information
loicmathieu committed Jan 14, 2025
1 parent 53b7e15 commit 25753fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public Flux<Event<LogEntry>> streamExecutionLogs(final String tenantId,
final AtomicReference<Runnable> disposable = new AtomicReference<>();

return Flux.<Event<LogEntry>>create(emitter -> {
// send a first "empty" event so the SSE is correctly initialized in the frontend in case there are no logs
emitter.next(Event.of(LogEntry.builder().build()).id("start"));

// fetch repository first
getExecutionLogs(tenantId, executionId, minLevel, List.of(), withAccessControl)
.forEach(logEntry -> emitter.next(Event.of(logEntry).id("progress")));
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/logs/TaskRunDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@
this.logsSSE = sse;
this.logsSSE.onmessage = event => {
this.logsBuffer = this.logsBuffer.concat(JSON.parse(event.data));
// we are receiving a first "fake" event to force initializing the connection: ignoring it
if (event.lastEventId !== "start") {
this.logsBuffer = this.logsBuffer.concat(JSON.parse(event.data));
}
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
Expand Down

0 comments on commit 25753fc

Please sign in to comment.