How can we reproduce the crash?
Hi,
The crash can be reproduced by running the below snippet:
import ffi from 'ffi-napi';
import ref from 'ref-napi';
const lib = ffi.Library('./lib', {
f: [ 'void', [] ],
});
console.log('Calling f()...');
try {
const res = lib.f();
console.log('Result:', res); // undefined for void-returning function
} catch (err) {
console.error('Error calling f():', err);
}
Relevant log output
root@KContainer:~/17481# bun run ffi_crash.mjs
============================================================
Bun Canary v1.3.11-canary.1 (9e93bfa1) Linux x64
Linux Kernel v5.10.0 | glibc v2.35
CPU: sse42 popcnt avx avx2
Args: "bun" "run" "ffi_crash.mjs"
Features: Bun.stderr(2) Bun.stdin(2) Bun.stdout(2) jsc napi_module_register(2) process_dlopen(2) unsupported_uv_function
Builtins: "bun:main" "node:assert" "node:fs" "node:os" "node:path" "node:process" "node:tty" "node:util"
Elapsed: 134ms | User: 77ms | Sys: 36ms
RSS: 1.11GB | Peak: 40.18MB | Commit: 1.11GB | Faults: 0 | Machine: 2.15TB
Bun encountered a crash when running a NAPI module that tried to call
the uv_thread_self libuv function.
Bun is actively working on supporting all libuv functions for POSIX
systems, please see this issue to track our progress:
https://github.com/oven-sh/bun/issues/18546
panic(main thread): unsupported uv function: uv_thread_self
https://bun.report/1.3.11/lr29e93bfaggmIugggCorzrmD6i75vEmu1Do56C89qDqmqtoE_izllkEmsv9jEs9i0sFmo7toE068voE2kqvoE___izllkEmsv9jEs9i0sFmo7toEA0eNorzSsuLSjILypJTVEoLVNIK81LLsnMz7NSKC2LL8koSk1MiS9OzUkDADmWD4A
Illegal instruction
Stack Trace (bun.report)
Bun v1.3.11-canary ([`9e93bfa`](<https://github.com/oven-sh/bun/tree/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8>)) on linux x86_64 [RunCommand]
**panic**: unsupported uv function: uv_thread_self
- [`crash_handler.zig:2265`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/crash_handler.zig#L2265>): `CrashHandler__unsupportedUVFunction`
- [`uv-posix-stubs.c:1750`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/uv-posix-stubs.c#L1750>): `uv_thread_self`
- `??`
- `??`
- `??`
- [`NapiClass.cpp:68`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/NapiClass.cpp#L68>): `long Zig::NapiClass_ConstructorFunction<false>`
- *1 unknown/js code*
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_op_call`
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_call_javascript`
- [`Interpreter.cpp:1320`](<https://github.com/oven-sh/WebKit/blob/00e825523d549a556d75985f486e4954af6ab8c7/Source/JavaScriptCore/interpreter/Interpreter.cpp#L1320>): `JSC::Interpreter::executeCallImpl`
- [`JSCommonJSModule.cpp:213`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L213>): `Bun::evaluateCommonJSModuleOnce`
- [`JSCommonJSModule.cpp:1371`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L1371>): `Bun::JSCommonJSModule::evaluate`
- [`JSCommonJSModule.h:94`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.h#L94>): `Bun::JSCommonJSModule::evaluate`
- [`ModuleLoader.cpp:801`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/ModuleLoader.cpp#L801>): `JSC::JSValue Bun::fetchCommonJSModuleNonBuiltin<false>`
- [`ModuleLoader.cpp:778`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/ModuleLoader.cpp#L778>): `Bun::fetchCommonJSModule`
- [`JSCommonJSModule.cpp:1288`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L1288>): `Bun::jsFunctionRequireCommonJS`
- *3 unknown/js code*
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_op_call`
- [`ld-temp.o:0`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/ld-temp.o#L0>): `llint_call_javascript`
- [`Interpreter.cpp:1320`](<https://github.com/oven-sh/WebKit/blob/00e825523d549a556d75985f486e4954af6ab8c7/Source/JavaScriptCore/interpreter/Interpreter.cpp#L1320>): `JSC::Interpreter::executeCallImpl`
- [`JSCommonJSModule.cpp:213`](<https://github.com/oven-sh/bun/blob/9e93bfa1b69a2f9b8c05acb15e02c5506dd4cbc8/src/bun.js/bindings/JSCommonJSModule.cpp#L213>): `Bun::evaluateCommonJSModuleOnce`
How can we reproduce the crash?
Hi,
The crash can be reproduced by running the below snippet:
Relevant log output
Stack Trace (bun.report)