Closed robertsLando closed 1 month ago
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
api/lib/logger.ts | 2 | 89.15% | ||
<!-- | Total: | 2 | --> |
Totals | |
---|---|
Change from base Build 11382077088: | 0.1% |
Covered Lines: | 3946 |
Relevant Lines: | 19889 |
I haven't tested yet, but what about other transports? Shouldn't console and stream transports be created only once as well?
@spudwebb good point, I focused on the filetransport but it makes sense to extend this to all transports list. Just submitted the fix
With this branch I now get the followings warnings in the console when I start ZUI
(node:21720) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Stream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21720) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [DailyRotateFile]. Use emitter.setMaxListeners() to increase limit
(node:21720) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [DailyRotateFile]. Use emitter.setMaxListeners() to increase limit
Here is what I get when I use --trace-warnings:
(node:48884) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 unpipe listeners added to [DailyRotateFile]. Use emitter.setMaxListeners() to increase limit
at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at _addListener (node:events:592:17)
at DailyRotateFile.addListener (node:events:610:10)
at DerivedLogger.Readable.pipe (C:\temp\zwave-js-ui\node_modules\winston\node_modules\readable-stream\lib\_stream_readable.js:584:8)
at DerivedLogger.add (C:\temp\zwave-js-ui\node_modules\winston\lib\winston\logger.js:364:10)
at C:\temp\zwave-js-ui\node_modules\winston\lib\winston\logger.js:124:44
at Array.forEach (<anonymous>)
at DerivedLogger.configure (C:\temp\zwave-js-ui\node_modules\winston\lib\winston\logger.js:124:18)
at setupLogger (C:\temp\zwave-js-ui\server\lib\logger.js:167:12)
@robertsLando I confirm that with this branch the original error I got at midnight when the files rotate is gone, but as stated above I now get a MaxListenersExceededWarning
node.js warning everytime I start.
if I detect that a transport needs to be recreated, I first destroy them: https://github.com/zwave-js/node-zwave-js/blob/37629fa0934b654d81b6c0e74ce6709dc0b61532/packages/core/src/log/shared.ts#L132-L143 and then create a new instance if necessary: https://github.com/zwave-js/node-zwave-js/blob/37629fa0934b654d81b6c0e74ce6709dc0b61532/packages/core/src/log/shared.ts#L206-L208 finally, I re-configure the log container: https://github.com/zwave-js/node-zwave-js/blob/37629fa0934b654d81b6c0e74ce6709dc0b61532/packages/core/src/log/shared.ts#L148
@spudwebb I will fix this asap, give me some time as I'm very full in this period
@robertsLando I'm not sure there is anything wrong with the way you implemented this. These warnings appear because of the number of module loggers in ZUI which now triggers the default 10 limit on event listeners on Stream
transport and DailyRotateFile
transport.
I saw that you can get rid of these warnings by increasing the number of max listeners, which seems to be what is done in the Console transport: https://github.com/search?q=repo%3Awinstonjs%2Fwinston%20setMaxListeners&type=code
So if I do the same thing in the customTransports
function for streamTransport
and fileTransport
then the warnings are gone.
streamTransport.setMaxListeners(30)
transportsList.push(streamTransport)
fileTransport.setMaxListeners(30)
transportsList.push(fileTransport)
@spudwebb Sorry, just found some time to look at this again, release is coming. Thanks again for your help 🙏🏼
Fixes #2937