From 82035d6b6afe8160d0503798c3fdc6ad6bf22f1d Mon Sep 17 00:00:00 2001 From: jreakin Date: Tue, 31 Mar 2026 23:42:53 -0500 Subject: [PATCH] fix(embeddings): also dispose ONNX session on error path If the embedding pipeline throws mid-run, the outer catch block only closed LadybugDB but left the ONNX Runtime session alive. Dispose it before closeLbug to prevent the same atexit race on the error path. Co-Authored-By: Claude Opus 4.6 (1M context) --- gitnexus/src/core/run-analyze.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitnexus/src/core/run-analyze.ts b/gitnexus/src/core/run-analyze.ts index 5d2684ec2..4ccfc8ad7 100644 --- a/gitnexus/src/core/run-analyze.ts +++ b/gitnexus/src/core/run-analyze.ts @@ -354,7 +354,14 @@ export async function runFullAnalysis( pipelineResult, }; } catch (err) { - // Ensure LadybugDB is closed even on error + // Ensure native resources are closed even on error to prevent + // C++ atexit destructor races during process.exit() (#38, #40). + try { + const { disposeEmbedder } = await import('./embeddings/embedder.js'); + await disposeEmbedder(); + } catch { + /* swallow */ + } try { await closeLbug(); } catch {