Commit 229ecf1
authored
fix(test): eliminate Winston uncaughtException listener leak (#3544)
* fix(test): eliminate Winston uncaughtException listener leak in jest test runs
Each jest.resetModules() call in beforeEach re-imports lib/services/logger.js,
creating a new Winston logger with handleExceptions:true. Winston registers a new
process.uncaughtException listener on every import but never removes orphaned
listeners from prior module registry generations. Across 1226 tests with
resetModules in beforeEach, this leaked ~570 listeners and ~285-1100MB of heap.
The billing PRs (#3535-#3539) amplified an existing pre-billing leak (162
instances) by +409 new instances (+252%) — pushing trawl_node past its 6144MB
cap.
Fix: guard handleExceptions with `process.env.NODE_ENV !== 'test'` on both the
Console transport (logger creation) and the File transport (setupFileLogger /
getLogOptions). Exception handling is preserved in production and development.
Also add `forceExit: true` to jest.config.js to prevent Jest from hanging on
open MongoDB handles from integration test afterAll disconnect races.
Verified: MaxListenersExceededWarning fully eliminated. 99 suites / 1226 tests
all pass.
* docs(logger): replace volatile metrics with stable explanation in handleExceptions guard1 parent 9d39136 commit 229ecf1
2 files changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
165 | 169 | | |
166 | 170 | | |
167 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | | - | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
0 commit comments