mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
* fix(sse): fix memory leaks in SSE stream cleanup and add memory telemetry * improvement(monitoring): add SSE metering to wand, execution-stream, and a2a-message endpoints * fix(workflow-execute): remove abort from cancel() to preserve run-on-leave behavior * improvement(monitoring): use stable process.getActiveResourcesInfo() API * refactor(a2a): hoist resubscribe cleanup to eliminate duplication between start() and cancel() * style(a2a): format import line Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(wand): set guard flag on early-return decrement for consistency --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
28 lines
803 B
TypeScript
28 lines
803 B
TypeScript
/**
|
|
* Tracks active SSE connections by route for memory leak diagnostics.
|
|
* Logged alongside periodic memory telemetry to correlate connection
|
|
* counts with heap growth.
|
|
*/
|
|
|
|
const connections = new Map<string, number>()
|
|
|
|
export function incrementSSEConnections(route: string) {
|
|
connections.set(route, (connections.get(route) ?? 0) + 1)
|
|
}
|
|
|
|
export function decrementSSEConnections(route: string) {
|
|
const count = (connections.get(route) ?? 0) - 1
|
|
if (count <= 0) connections.delete(route)
|
|
else connections.set(route, count)
|
|
}
|
|
|
|
export function getActiveSSEConnectionCount(): number {
|
|
let total = 0
|
|
for (const count of connections.values()) total += count
|
|
return total
|
|
}
|
|
|
|
export function getActiveSSEConnectionsByRoute(): Record<string, number> {
|
|
return Object.fromEntries(connections)
|
|
}
|