Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: re-use file transport instance when setup loggers #3928

Merged
merged 7 commits into from
Oct 17, 2024
Merged

Conversation

robertsLando
Copy link
Member

Fixes #2937

@coveralls
Copy link

coveralls commented Oct 7, 2024

Pull Request Test Coverage Report for Build 11382649159

Details

  • 24 of 24 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 21.101%

Files with Coverage Reduction New Missed Lines %
api/lib/logger.ts 2 89.15%
Totals Coverage Status
Change from base Build 11382077088: 0.1%
Covered Lines: 3946
Relevant Lines: 19889

💛 - Coveralls

@spudwebb
Copy link
Contributor

spudwebb commented Oct 7, 2024

I haven't tested yet, but what about other transports? Shouldn't console and stream transports be created only once as well?

@robertsLando
Copy link
Member Author

@spudwebb good point, I focused on the filetransport but it makes sense to extend this to all transports list. Just submitted the fix

@spudwebb
Copy link
Contributor

spudwebb commented Oct 7, 2024

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)

@spudwebb
Copy link
Contributor

spudwebb commented Oct 8, 2024

@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.

@robertsLando
Copy link
Member Author

robertsLando commented Oct 9, 2024

@spudwebb
Copy link
Contributor

spudwebb commented Oct 9, 2024

@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)

@robertsLando
Copy link
Member Author

@spudwebb Sorry, just found some time to look at this again, release is coming. Thanks again for your help 🙏🏼

@robertsLando robertsLando merged commit ded941b into master Oct 17, 2024
9 checks passed
@robertsLando robertsLando deleted the fix-logger branch October 17, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error while fetching store files: EPERM
3 participants