ipfs/helia-http-gateway

fix: uncaughtException needs more best practices

Closed this issue · 2 comments

Tasks

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

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.

Fixed by #154