Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: max listeners warning (#316)
Browse files Browse the repository at this point in the history
The query timeout controller signal gets passed to all of the network operations etc that run during a query so can end up with lots of listeners for it's 'abort' event, which can trigger `MaxListenersExceededWarning` in node which warns of a memory leak, even though there is no leak.
  • Loading branch information
achingbrain authored Apr 17, 2022
1 parent d5b114e commit 18ba9c0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/query/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ export class QueryManager implements Startable, Initializable {
// don't let queries run forever
timeoutController = new TimeoutController(DEFAULT_QUERY_TIMEOUT)
options.signal = timeoutController.signal

// this signal will get listened to for network requests, etc
// so make sure we don't make a lot of noise in the logs
try {
if (setMaxListeners != null) {
setMaxListeners(Infinity, timeoutController.signal)
}
} catch {} // fails on node < 15.4
}

// allow us to stop queries on shut down
Expand All @@ -106,7 +114,7 @@ export class QueryManager implements Startable, Initializable {
// so make sure we don't make a lot of noise in the logs
try {
if (setMaxListeners != null) {
setMaxListeners(0, signal)
setMaxListeners(Infinity, signal)
}
} catch {} // fails on node < 15.4

Expand Down

0 comments on commit 18ba9c0

Please sign in to comment.