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

Commit 18ba9c0

Browse files
authored
fix: max listeners warning (#316)
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.
1 parent d5b114e commit 18ba9c0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/query/manager.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ export class QueryManager implements Startable, Initializable {
8989
// don't let queries run forever
9090
timeoutController = new TimeoutController(DEFAULT_QUERY_TIMEOUT)
9191
options.signal = timeoutController.signal
92+
93+
// this signal will get listened to for network requests, etc
94+
// so make sure we don't make a lot of noise in the logs
95+
try {
96+
if (setMaxListeners != null) {
97+
setMaxListeners(Infinity, timeoutController.signal)
98+
}
99+
} catch {} // fails on node < 15.4
92100
}
93101

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

0 commit comments

Comments
 (0)