-
-
Notifications
You must be signed in to change notification settings - Fork 335
Closed
Description
#[napi(catch_unwind)]
pub async fn panic_immediately() -> NapiResult<()> {
panic!("This is a test panic");
}
async function callPanic() {
// Expected: throw error, actual: hang forever
await panicImmediately();
console.log('Done panicing');
}
I expected the panicImmediately
function to return a promise that would be rejected after the rust code ran. However, it appears that the promise hangs forever. catch_unwind
in the napi
macro has no effect one way or the other.
I think this is a dangerous default behavior because a hanging promise may block a server forever. It would be nicer if it rejected the promise with some kind of error, so we could log and cleanly shut the server down. Crashing the entire process might be another reasonable default. If this behavior is the desired default, it would be good to document it prominently.
I could work around this by wrapping everything inside of #[napi]
with std::panic::catch_unwind
, but this feels risky.
Metadata
Metadata
Assignees
Labels
No labels