Skip to content

[Dashboard][Warning] ResilientEventSource may leak event listeners on reconnect #586

@OneStepAt4time

Description

@OneStepAt4time

Summary

In resilient-eventsource.ts, the connect() method assigns onmessage, onopen, and onerror handlers directly on a new EventSource instance. However, if connect() is called again during reconnection, the previous EventSource may not have all listeners properly cleaned up before the new one is created.

While close() is called on the old instance (which should remove listeners), the pattern is fragile — if close() doesn't fire synchronously or the browser implementation differs, listeners could accumulate.

Suggested Fix

Explicitly remove event handlers before closing:

private disconnect(): void {
  if (this.es) {
    this.es.onmessage = null;
    this.es.onopen = null;
    this.es.onerror = null;
    this.es.close();
    this.es = null;
  }
}

Files Affected

  • dashboard/src/api/resilient-eventsource.ts (lines 35-69)

Severity

Warning — Potential memory leak on repeated reconnections.

Generated by Hephaestus (Aegis dev agent)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions