Skip to content
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

Merged
merged 7 commits into from
Oct 17, 2024

Conversation

Ndpnt
Copy link
Member

@Ndpnt Ndpnt commented Oct 15, 2024

No description provided.

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
@Ndpnt Ndpnt force-pushed the increase-logging-error-resistance branch from dab92e2 to 19de91f Compare October 15, 2024 16:01
@Ndpnt Ndpnt requested a review from MattiSG October 15, 2024 16:02
Copy link
Member

@MattiSG MattiSG left a 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? 😅

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -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,
Copy link
Member

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? 🤔 😅

Copy link
Member Author

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.

@Ndpnt
Copy link
Member Author

Ndpnt commented Oct 16, 2024

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? 😅

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.
So the behavior is kept the same!

Co-authored-by: Matti Schneider <matti@opentermsarchive.org>
@Ndpnt Ndpnt merged commit eb93442 into main Oct 17, 2024
8 checks passed
@Ndpnt Ndpnt deleted the increase-logging-error-resistance branch October 17, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants