Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/event-emitter-listener-limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# EventEmitter listener limit

`NetworkClass` sets a higher listener limit by calling `this.setMaxListeners(100)` in its constructor.
This enables many modules to attach network event handlers without triggering Node's default
`MaxListenersExceededWarning` after ten listeners. The value of 100 was selected as a reasonable upper bound.

If the application logs show `MaxListenersExceededWarning`, review the registered events and consider
adjusting the limit accordingly.
5 changes: 5 additions & 0 deletions src/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export class NetworkClass extends EventEmitter {

constructor(config: Shardus.StrictServerConfiguration, logger: Logger) {
super()
// Allow more listeners to attach to this EventEmitter to avoid memory leak warnings
// if various modules register network-related events.
// 100 was chosen as a reasonable upper bound; monitor logs for MaxListenersExceeded warnings
// and adjust if needed.
this.setMaxListeners(100)
this.app = express()
this.sn = null
this.logger = logger
Expand Down
Loading