onnxruntime
5eabb963 - [Node.js] Avoid duplicate N-API cleanup hook registration (#32469)

Commit
51 days ago
[Node.js] Avoid duplicate N-API cleanup hook registration (#32469) ### Description - Retain the native ORT singleton and register its N-API cleanup hook only once per `napi_env`. - Continue refreshing the Tensor constructor on every `initOrtOnce()` call, preserving module-reload behavior. - Keep initialization independent across Node.js worker environments. - Add a standalone regression test that calls `initOrtOnce()` twice, verifies that the latest Tensor constructor is used, and requires a normal process exit. ### Motivation and Context Calling the native `initOrtOnce()` export more than once in the same environment registered the same N-API cleanup hook twice. Recent Node.js versions assert on that duplicate registration and abort the process. The guard is deliberately scoped to retaining the singleton and registering the cleanup hook. Per-environment binding state, including the Tensor constructor, is still refreshed on repeated calls. Fixes #32464 ### Testing - Verified that the original two-call reproducer changes from exit code 134 to a normal code-0 exit. - Ran the relevant Node API and lifecycle tests: 22 passing. - Ran the standalone and worker tests after strengthening signal-termination detection: 9 passing. - Ran ESLint, Prettier, clang-format, the TypeScript project checks, and `git diff --check`.
Author
Parents
Loading