-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Segmentation fault at exit #12653
Comments
We will need a reproduction to be able to fix this. Please provide the JS file + the code we can use to compile an lib to use for FFI. |
JS test case: const dylib = Deno.dlopen('libCrash.so', {
"call_non_blocking": { parameters: ["buffer", "usize", "buffer", "usize"], result: "u32", nonblocking: true },
});
// cleanup on exit
globalThis.addEventListener('unload', async () => {
try {
// Without this line, it does not segfault
await invoke_ffi();
dylib.close()
} catch (e) {
console.log(e)
}
console.log('terminated.')
})
async function invoke_ffi() {
const args = new Uint8Array(1);
args[0] = "A".charCodeAt(0)
const res = new Uint8Array(1);
const status = await dylib.symbols.call_non_blocking(args, args.length, res, res.length);
if (status !== 0) {
throw Error('Invalid')
}
return new TextDecoder().decode(res)
}
console.log(await invoke_ffi()) Rust FFI library: use std::{thread, time};
#[no_mangle]
pub extern "C" fn call_non_blocking(
args: *const u8,
args_len: usize,
res: *mut u8,
res_len: usize,
) -> u32 {
let args = unsafe { std::slice::from_raw_parts(args, args_len) };
let res = unsafe { std::slice::from_raw_parts_mut(res, res_len) };
// Without this line, it does not segfault
thread::sleep(time::Duration::from_millis(30));
res.copy_from_slice(args);
0
} |
The output of the above is: deno run -A --unstable ./ffi.js
A
Segmentation fault |
This reproduces with latest 1.16.0 |
Can you please prioritize this issue? It affects running unit tests in CI because of the non zero return code. |
If you register an I suspect this can also be an issue with terminating/closing workers. |
Related to #12341. |
To confirm: this is indeed what happens. I would hesitate to call it a bug but it's an unfortunate interaction between subsystems. The synchronous nature of "unload" shouldn't change and rejecting async functions is sub-optimal. Deno could perhaps print a warning if the promise is still pending. Example: // not a problem: no await points, effectively synchronous
addEventListener("unload", async () => console.log("bye"))
// this however _is_ a problem and should probably warn
addEventListener("unload", () => new Promise(k => setTimeout(k))) |
Not executing a callback is fine, crashing it is not. |
Project running under Deno 1.15.3 on Linux x64 will segfault at exit.
The stack trace is:
Thread list
Project is using non-blocking FFI
The text was updated successfully, but these errors were encountered: