-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Bug]: File transport stops logging during rotate and leaks memory #2452
Comments
I'm open to a PR if you think something like your suggestion would be a reliable fix. You have looked more closely at this code than I have lately. Would it be better to try some kind of |
I plan to test this a bit before it should be reviewed/merged. |
Amazing, thank you!! Keep us posted :) |
I tested it overnight and no issues. Does it matter that the coverage reduced by 0.02%? The line count went down by 1 and it was a covered line. |
I encountered the same problem under high load. Please merge it. |
🔎 Search Terms
file leak memory
The problem
The Winston file transport occasionally will stop logging immediately after log rotation. This results in the new log file being size 0, the logger WritableState stuck in "writing" state with continuously increasing buffer. All transports for the logger are blocked. Eventually this leads to an out of memory and program crash.
This appears to be caused by:
eventNames
still returns all keys set to undefined. events.js#L89eventNames('rotate')
to determine whether to emit the event or set_rotate
false. file.ts#L442To confirm this, I added a debug log inside the
once('open'
:And eventually, after over an hour of logging, this log appeared:
Additionally I opened the inspector and observed the shapeMode symbol was set to true on the _stream PassThrough.
I am not sure why the shapeMode is set to true, but apparently eventNames() cannot be relied upon. For current event listeners. Possibly the file.js
if (this._stream.eventNames().includes('rotate')) {
should be replaced with
if (this._stream.listenerCount('rotate')) {
which will return 0 when there are no rotate listeners.
Additional versions:
[email protected]
[email protected]
What version of Winston presents the issue?
v3.13.0
What version of Node are you using?
20.11.1
If this worked in a previous version of Winston, which was it?
No response
Minimum Working Example
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: