Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Panic in async function causes returned promise to hang forever.  #2047

@adamfaulkner-at

Description

@adamfaulkner-at
#[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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions