diff --git a/src/core/homebridge-ipc/homebridge-ipc.service.ts b/src/core/homebridge-ipc/homebridge-ipc.service.ts index 114e2b702..8ddc6cf34 100644 --- a/src/core/homebridge-ipc/homebridge-ipc.service.ts +++ b/src/core/homebridge-ipc/homebridge-ipc.service.ts @@ -28,6 +28,8 @@ export class HomebridgeIpcService extends EventEmitter { public setHomebridgeProcess(process: ChildProcess) { this.homebridge = process; + this.homebridge.setMaxListeners(this.homebridge.getMaxListeners() + 2); + this.homebridge.on('message', (message: { id: string; data: unknown }) => { if (typeof message !== 'object' || !message.id) { return; @@ -57,14 +59,17 @@ export class HomebridgeIpcService extends EventEmitter { const actionTimeout = setTimeout(() => { // eslint-disable-next-line @typescript-eslint/no-use-before-define this.removeListener(responseEvent, listener); + this.setMaxListeners(this.getMaxListeners() - 1); reject('The Homebridge service did not respond'); }, 3000); const listener = (data: any) => { clearTimeout(actionTimeout); + this.setMaxListeners(this.getMaxListeners() - 1); resolve(data); }; + this.setMaxListeners(this.getMaxListeners() + 1); this.once(responseEvent, listener); this.sendMessage(requestEvent); }); diff --git a/src/modules/child-bridges/child-bridges.service.ts b/src/modules/child-bridges/child-bridges.service.ts index 9f5542266..f27159330 100644 --- a/src/modules/child-bridges/child-bridges.service.ts +++ b/src/modules/child-bridges/child-bridges.service.ts @@ -38,15 +38,19 @@ export class ChildBridgesService { client.emit('child-bridge-status-update', data); }; + this.homebridgeIpcService.setMaxListeners(this.homebridgeIpcService.getMaxListeners() + 1); this.homebridgeIpcService.on('childBridgeStatusUpdate', listener); // cleanup on disconnect const onEnd = () => { client.removeAllListeners('end'); client.removeAllListeners('disconnect'); + client.setMaxListeners(client.getMaxListeners() - 2); this.homebridgeIpcService.removeListener('childBridgeStatusUpdate', listener); + this.homebridgeIpcService.setMaxListeners(this.homebridgeIpcService.getMaxListeners() - 1); }; + client.setMaxListeners(client.getMaxListeners() + 2); client.on('end', onEnd.bind(this)); client.on('disconnect', onEnd.bind(this)); }