-
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
fix memory leak issue for winston.defaultLogger #2134
Conversation
@wbt @DABH @maverick1872 If you have time, could you help look at this PR to fix issue #2114. Maybe has two solutions for this issue,
|
First, thanks for submitting a PR with screenshots demonstrating the test result! I am not a fan of adding the console transport by default, having previously run into issues where a process logging too much to console was leading a journal file to fill up hard drive space and crash a server, while Winston logs with daily-rotate-file maintained a roughly constant and reasonable disk-space use. I think this could be a breaking change for some setups. However, if adding the console transport fixes the issue for your setup without causing new issues, I would say by all means go for it in your application code, and consider a PR to modify documentation pointing others to the solution. There is likely a better solution to fix the underlying issue, but I don't think this workaround should be merged into the main codebase. |
hi @wbt, In your example which filled up the hdd space, if there was no default console logger, would that be a memory leak problem instead of disk space problem? |
Yes, I understand maybe the user uses the default logger exposed by require('winston'), always add transport later. Because if no transport what point of logging. Maybe modify documentation add warning for no transport is fine. But how about with this in the default logger? const defaultLogger = exports.createLogger({
transports: [new exports.transports.Console(
{
level: 'error',
silent: true
}
)]
}); |
I think @wbt maybe mean, that if add console into default logger, user adds file transport later, now default logger will have two transports. |
@wbt Thinking about this, documentation is best choocie. Will close this one and create PR for documentation... |
Nope. The other process was written in a different language and not using Winston, and had no identified memory leak problem. The key factor for the comparison is that it was logging a lot to console and that volume of logging to console caused a server-crashing HDD fill. I don't think suddenly making a large number of Winston-logged processes have that problem too would be a good idea. However, if a specific Winston-logged app has a setup where adding a lot to console would definitely not cause an issue, that app is welcome to implement this easy workaround at least until the underlying issue gets fixed. |
Fix memory leak issue related to #2114, this is found in our prod.
From heap dump,
defaultLogger
clearly has a strings leak issue and these strings are log strings in my test case. And all logs seem to be kept inlogger._writableState.buffer
if no transport is configured.I dig a little bit into history seems 3e3b43c#diff-e71cd9aaf26c1886e8bb0233d74710a47c1d32c203ad80baffc901c3073f604e remove Console transport from
defaultLogger
.So I added it back.
Below are two memory heaps,
The log string object
distance
is too large and chain bynext
which probability hold bylogger._writableState.buffer
.Heap dump: Heap-winston3.7.2.zip
Heap dump: Heap-fixedversion.zip
Test code