This commit is contained in:
jarek committed 2026-03-02 07:59:58 +01:00
1 parent 4b430340db
commit 9c451aedf9
120 files changed
+7777 -6046

No files matched your search

+17 -9
View File
@@ -2,17 +2,25 @@
* Container Event Emitter
*
* Shared EventEmitter for broadcasting container events to SSE clients.
* Events are emitted by the subprocess-manager when it receives them from the event-subprocess.
* Events are emitted by the collection worker when processing Docker events.
*
* IMPORTANT: Uses globalThis to ensure a single instance across all module imports.
* In Vite dev mode and SvelteKit production builds, server modules can be loaded
* multiple times (HMR, chunking), creating separate EventEmitter instances.
* Using globalThis guarantees emitters and listeners share the same object.
*/
import { EventEmitter } from 'node:events';
// Event emitter for broadcasting new events to SSE clients
// Used by:
// - subprocess-manager.ts: emits events received from event-subprocess via IPC
// - api/activity/events/+server.ts: listens for events to broadcast via SSE
export const containerEventEmitter = new EventEmitter();
const GLOBAL_KEY = '__dockhand_container_event_emitter__';
// Allow up to 100 concurrent SSE listeners (default is 10)
// This prevents MaxListenersExceededWarning with many dashboard clients
containerEventEmitter.setMaxListeners(100);
// Ensure single instance via globalThis
if (!(globalThis as any)[GLOBAL_KEY]) {
const emitter = new EventEmitter();
// Allow up to 100 concurrent SSE listeners (default is 10)
// This prevents MaxListenersExceededWarning with many dashboard clients
emitter.setMaxListeners(100);
(globalThis as any)[GLOBAL_KEY] = emitter;
}
export const containerEventEmitter: EventEmitter = (globalThis as any)[GLOBAL_KEY];