-
Notifications
You must be signed in to change notification settings - Fork 30
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
Prevent the engine from exiting on non-critical SMTP errors from the logger #1109
Conversation
Use the `error` event for error handling instead of the `exitOnError` option, which can also be a function to conditionally exit on certain errors. Relying on `exitOnError` introduces a 3-second delay before shutdown, during which asynchronous operations may still execute, leading to potential unintended side effects. See https://github.com/winstonjs/winston/blob/195e55c7e7fc58914ae4967ea7b832c9e0ced930/lib/winston/exception-handler.js#L222
dab92e2
to
19de91f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the implementation, but I am concerned that we change the behavior significantly: we now exit on every logging error except SMTP ones, whereas before we exited only one SMTP logging errors. Why not simply never exitOnError
? 😅
@@ -51,7 +62,6 @@ if (config.get('@opentermsarchive/engine.logger.sendMailOnError')) { | |||
ssl: true, | |||
timeout: 30 * 1000, | |||
formatter: args => args[Object.getOwnPropertySymbols(args)[1]], // Returns the full error message, the same visible in the console. It is referenced in the argument object with a Symbol of which we do not have the reference but we know it is the second one. | |||
exitOnError: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't we simply implement the whole thing by removing this line? 🤔 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove this line while keeping rejectionHandlers
defined, Winston will catch all uncaughtException
events without exiting the process, which is not the intended behavior. By default, both Node.js and Winston terminate the process when an uncaughtException
occurs, as these are considered programmer errors. And this is the correct approach. As explained here, crashing immediately is the best way to handle programmer errors.
I agree that the previous code may have given the impression that we were exiting only on SMTP logging errors, but that wasn’t actually the case. Once exitOnError is set to true, the process will exit for any type of error, not just those from a specific transport. Also, I’m not sure this option is available at the transport level—it seems to be only available at the logger level. I believe the previous configuration at the transport level was a mistake. |
Co-authored-by: Matti Schneider <[email protected]>
No description provided.