Skip to content

Commit

Permalink
Mitigate event emitter "memory leak" warnings when a significant numb…
Browse files Browse the repository at this point in the history
…er of HSV events occur simultaneously. (#1029)
  • Loading branch information
hjdhjd committed Apr 28, 2024
1 parent 5cab65c commit 19f80ab
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/datastream/DataStreamServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ export class DataStreamConnection extends EventEmitter {
this.state = ConnectionState.EXPECTING_HELLO;

// below listener is removed in .close()
this.connection.setMaxListeners(this.connection.getMaxListeners() + 1);
this.connection.on(HAPConnectionEvent.CLOSED, this.hapConnectionClosedListener); // register close listener

debug("[%s] Registering CLOSED handler to HAP connection. Connection currently has %d close handlers!",
Expand Down Expand Up @@ -1139,6 +1140,7 @@ export class DataStreamConnection extends EventEmitter {
this.emit(DataStreamConnectionEvent.CLOSED);

this.connection?.removeListener(HAPConnectionEvent.CLOSED, this.hapConnectionClosedListener);
this.connection?.setMaxListeners(this.connection.getMaxListeners() - 1);
this.removeAllListeners();
}

Expand Down

0 comments on commit 19f80ab

Please sign in to comment.