Skip to content

Commit dba262d

Browse files
committed
Fix ONNX shutdown crash: disable global thread pool via session options
Set intraOpNumThreads/interOpNumThreads: 1 on every ONNX session. With these options onnxruntime-node uses per-session single threads instead of the global thread pool. The global pool destructor has a use-after-free mutex bug on macOS (libc++ 'Invalid argument' crash during process exit). With no global pool created, the crash is gone.
1 parent 70d502e commit dba262d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/lib/embedder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export async function loadModel(
4040

4141
const pipeOpts: Record<string, unknown> = {};
4242
if (config.dtype) pipeOpts.dtype = config.dtype;
43+
// Use per-session threads (intraOpNumThreads: 1) instead of the global ONNX thread pool.
44+
// The global thread pool destructor crashes on macOS (libc++ mutex Invalid argument) during
45+
// process exit. With intraOpNumThreads: 1 the global pool is never created.
46+
pipeOpts.session_options = { intraOpNumThreads: 1, interOpNumThreads: 1 };
4347

4448
const pipe = await pipeline('feature-extraction', config.model, pipeOpts);
4549
_pipeCache.set(cacheKey, pipe);

0 commit comments

Comments
 (0)