Repository navigation
Conversation
getLogger() appended a random number to the category before calling winston.loggers.get(). winston's container keeps every id for the life of the process, so every APIContracts/APIControllers object registered a new logger that was never freed (~5 loggers and ~57KB of heap per request/controller pair). Long-running servers grew until they ran out of heap. Fixes AuthorizeNet#113 and AuthorizeNet#97. Key the logger on the category plus its logger settings (enabled, level, location) instead. The same settings reuse one logger, and different settings, such as an externalConfig, still get their own, since winston.loggers.get() ignores options for an existing id. Return the existing logger early so file transports are not rebuilt on every call when logging is enabled.
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.
Fixes #113. Also fixes #97.
Problem
Since 1.0.9,
getLogger()inlib/logger.jsappends a random number to the logger category before callingwinston.loggers.get(). winston'sContainerkeeps every id for the life of the process, so everyAPIContracts.*/APIControllers.*object registers a new logger that is never reused or freed. This happens even when logging is disabled, which is the default.Each request/controller pair keeps 5 loggers and about 57KB of heap. Long-running servers grow until they run out of heap. In our production payment service this crashed Node 6 times in one day.
Fix
Key the logger on the category plus its logger settings (
enabled,level,location) instead of a random number:winston.loggers.get()ignoresoptionsfor an existing id, which I assume is why the random suffix was added.Log labels now show the plain category name (e.g.
ApiOperationBase) instead ofApiOperationBase483920117.Results
Request + controller pairs (
GetTransactionDetails), no network, yielding to the event loop between batches, heap measured after GC (Node v25.2.1):Tests
New
test/test-logger.js. It runs offline with no sandbox credentials:npx mocha test/test-logger.js: 3 passing with this change. Without it, 2 tests fail. The new test file passes eslint. The 2 eslint errors inlib/logger.js(semi,no-prototype-builtins) were already onmaster, and I left them alone to keep the diff small.