Fix/http transport memory leak#2565
Open
yash-dayama wants to merge 5 commits intowinstonjs:masterfrom
Open
Conversation
- Remove unnecessary setImmediate wrapper in Console transport log method - Add stress tests to verify memory usage and event listener cleanup - Fix issue winstonjs#2548
DABH
requested changes
Aug 12, 2025
Contributor
DABH
left a comment
There was a problem hiding this comment.
A few questions and comments here
| log(info, callback) { | ||
| // Handle callback immediately since HTTP requests are already async | ||
| if (callback) { | ||
| return callback(); |
Contributor
There was a problem hiding this comment.
Why would we return here if there's a call back? We would then exit the function before anything is logged?
| _doBatch(options, callback, auth, path) { | ||
| // Handle callback immediately since batching is async | ||
| if (callback) { | ||
| return callback(); |
Contributor
There was a problem hiding this comment.
Please revert changes to this file
Contributor
There was a problem hiding this comment.
Please delete this file from this PR as it's part of your other PR #2564
| // First message stored, start the timeout | ||
| this.batchTimeoutID = setTimeout(() => { | ||
| this.batchTimeoutID = -1; | ||
| this._doBatchRequest(null, auth, path); |
Contributor
There was a problem hiding this comment.
Why is null passed rather than callback?
| // max batch count reached, send immediately | ||
| clearTimeout(this.batchTimeoutID); | ||
| this.batchTimeoutID = -1; | ||
| this._doBatchRequest(null, auth, path); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Memory Leaks in Console and HTTP Transports
Description
This PR fixes memory leak issues in both the Console and HTTP transports that occur when logging a large number of messages in quick succession. The issues were reported in #2548 and #2465, affecting Winston 3.x.x versions.
Problems
Console Transport:
setImmediateto emit the 'logged' event created many pending operationsHTTP Transport:
Solutions
Console Transport:
setImmediatewrapper since console writes are already asyncHTTP Transport:
Changes
setImmediatewrapper in Console transport's log methodTesting
Added new stress tests that:
To run the tests:
Related Issues
Backwards Compatibility
These changes maintain full backwards compatibility as they only optimize internal operations without changing the transports' APIs or behaviors.