Fixes file descriptor leak in certain use cases#1113
Fixes file descriptor leak in certain use cases#1113lamweili merged 6 commits intolog4js-node:masterfrom
Conversation
- subsequent log4js.configure() will run log4js.shutdown() first - log4js.shutdown() will always clear/reset existing appenders and categories
|
@peteriman you marked #1005 as fixed by this, but are you sure that is the case? I saw your comment in the thread, but have not had time to verify it. |
|
@thernstig I'm quite sure there were multiple concurrent Nevertheless, please take some time to verify my comments in #1005. Read onwards for the rationale of this fix:The issue is due to Lines 90 to 95 in 52185a4
log4js-node/lib/appenders/file.js Lines 78 to 81 in 52185a4 On the second The fix resets the appenders, releasing the resources. // Clone out to maintain a reference
const appendersToCheck = Array.from(appenders.values());
+ // Reset immediately to prevent leaks
+ appenders.init();
+ categories.init();
// Call each of the shutdown functions in parallel
const shutdownFunctions = appendersToCheck.reduceRight(
(accum, next) => (next.shutdown ? accum + 1 : accum),
0
); |
|
I think it looks good, not sure if @nomiddlename wants to LGTM this or not. |
|
@thernstig Your questions were of great help. I should add a few more automated test cases to cover those. |
f6d6acc to
0c683b7
Compare
…back to initial state on log4js.shutdown()
0c683b7 to
2333054
Compare
098759e to
96f198b
Compare
|
Released in |
Fixes #788, Fixes #978, Fixes #1005, Fixes #1058
Additionally, this PR supersedes PR #1083
Allow multiple configure() calls:
Calling multiple
configure()withoutshutdown()may leave resources open (file handles, network connections, etc).This patch explicitly does a
shutdown()for subsequentlyconfigure()to prevent resource leaks.Allow multiple shutdown() calls:
Within the
shutdown(), it now clearsappendersandcategories. Repeated/duplicatedshutdown()calls will no longer traverse the sameappendersto shut them down them again which will result inError [ERR_STREAM_WRITE_AFTER_END]: write after end.