feat(socket): add configurable maxListeners to prevent memory leaks

Based on RSocket's battle-tested configuration:

- Add maxWebSocketListeners config option (default: 20)
  - 8 base WS events + 10 dynamic listeners + 2 buffer slots
- Add maxSocketClientListeners config option (default: 50)
- Replace dangerous setMaxListeners(0) with configurable limits
- Add warning log if user explicitly sets limit to 0

BREAKING: Previous behavior used setMaxListeners(0) which removed
all limits. Now defaults to safe limits but can be overridden via config.
This commit is contained in:
Claude
2026-01-20 05:19:22 +00:00
parent 4f623b4942
commit 3afb8b80c5
4 changed files with 34 additions and 3 deletions
+5 -1
View File
@@ -80,7 +80,11 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
cachedGroupMetadata: async () => undefined,
makeSignalRepository: makeLibSignalRepository,
// Circuit breaker configuration
enableCircuitBreaker: true
enableCircuitBreaker: true,
// Listener limits (memory leak prevention)
// 8 base WS events + 10 dynamic listeners + 2 buffer slots
maxWebSocketListeners: 20,
maxSocketClientListeners: 50
}
export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {