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
log4js version 2.10.0 is giving error when shutdown and process Exit called #788
Comments
This issue might give you more information: #542 - the problem is that process.exit happens synchronously, before the appenders have finished their final writes. You could try adding a setTimeout call around the process.exit and waiting a second or two? |
I am calling process.exit asynchronously in shutdown callback. It not a synchronous request and whatever the scenario is , it should not give exception. right?? |
Closing this one, because as mentioned in #542 there's not a lot we can do about it. |
@nomiddlename Could you elaborate this a bit more. In #542 the initial post says:
But according to https://nodejs.org/api/process.html#process_process_exit_code it is called synchronously. This makes that issue harder to understand, because one cannot be sure you are talking the same lingo. Is the real problem this? When the callback of |
Yep, you're right - process.exit is synchronous and terminates any pending asynchronous operations. |
@nomiddlename Then how is it that the original poster's concern is not valid? If the callback of And to follow up that question. If |
Is this a problem you're encountering with the latest version of log4js? If so, have you got some code that reproduces the issue? I can then see if we can fix this or not. |
@nomiddlename Let me upgrade my version first to see if this is a problem. I just read into your previous answer that this is not solvable, but if you are saying that the latest version should not have this problem then I will definitely try an upgrade and see how it goes. It might take a while, but I will get back to you once I get the time, but I will upgrade! |
If you are having this issue, make sure you are not running log4js.shutdown more than once in parallel. I had such errors when I was running log4js.shutdown several times before it has time to complete the async handler. |
#1113 fixed this issue in |
code:
log4js.shutdown(() => { process.exit(1); });
Error:
log4js.fileAppender - Writing to file ../logs/ABC.log, error happened Error: write after end
at writeAfterEnd (/node_modules/readable-stream/lib/_stream_writable.js:288:12)
at RollingFileStream.Writable.write (/node_modules/readable-stream/lib/_stream_writable.js:332:20)
at Function.app.shutdown (node_modules/log4js/lib/appenders/file.js:69:12)
at appenders.filter.forEach.a (/node_modules/log4js/lib/log4js.js:273:52)
at Array.forEach (native)
at Object.shutdown (/node_modules/log4js/lib/log4js.js:273:37)
at process.exitHandler (XYZ.js:130:12)
at emitOne (events.js:96:13)
at process.emit (events.js:188:7)
at process.exit (internal/process.js:146:15)
The text was updated successfully, but these errors were encountered: