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

fix: uncaughtException needs more best practices #112

Closed
4 tasks
SgtPooki opened this issue Apr 4, 2024 · 2 comments
Closed
4 tasks

fix: uncaughtException needs more best practices #112

SgtPooki opened this issue Apr 4, 2024 · 2 comments

Comments

@SgtPooki
Copy link
Member

SgtPooki commented Apr 4, 2024

Tasks

Preview Give feedback

const uncaughtHandler = (error: any): void => {
log.error('Uncaught Exception:', error)
if (ALLOW_UNHANDLED_ERROR_RECOVERY && (RECOVERABLE_ERRORS === 'all' || RECOVERABLE_ERRORS.includes(error?.code) || RECOVERABLE_ERRORS.includes(error?.name))) {
log.trace('Ignoring error')
return
}
void closeGracefully('SIGTERM')
}

related:

cc @achingbrain

@achingbrain
Copy link
Member

achingbrain commented Apr 5, 2024

Add default known-recoverable uncaughtExceptions

There are no recoverable uncaught exceptions. This is clearly documented:

The event should not be used as an equivalent to On Error Resume Next. Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues.

The correct use of 'uncaughtException' is to perform synchronous cleanup of allocated resources (e.g. file descriptors, handles, etc) before shutting down the process. It is not safe to resume normal operation after 'uncaughtException'.

https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly

Note:

It is not safe to resume normal operation after 'uncaughtException'.

yet this is exactly what #102 does.

@achingbrain
Copy link
Member

Fixed by #154

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

No branches or pull requests

2 participants