Skip to content

fix(native): throw instead of aborting on calls to a closed handle - #10

Merged
AlexanderSlaa merged 1 commit into
mainfrom
fix/closed-handle-abort
Nov 21, 2026
Merged

AlexanderSlaa merged 1 commit into
mainfrom
fix/closed-handle-abort

Conversation

@AlexanderSlaa

Copy link
Copy Markdown
Contributor

Fixes #7.

Problem

Synchronous methods call HandleState::use() on the main thread, which throws std::runtime_error("resource is closed") once the handle is closed. node-addon-api only converts Napi::Error into a JavaScript exception, so the std::runtime_error escaped and the process aborted with SIGABRT:

terminate called after throwing an instance of 'std::runtime_error'
  what():  resource is closed

Affected: IoContext.setNamespace(), setLocatorKey(), setReadSnapshot(), poolId, lastVersion and Cluster.config(), instanceId, ioContext() on a closed handle.

Fix

Define NODE_ADDON_API_CPP_EXCEPTIONS_ALL in binding.gyp and CMakeLists.txt. node-addon-api then converts any std::exception thrown from a callback into a JavaScript Error with its message. Calls on a closed handle now throw Error: resource is closed, the same error the async methods already reject with. It also covers any other std::exception (such as std::bad_alloc) thrown on the main thread.

Tests

Added an integration test that calls all eight members on closed handles and expects them to throw.

Against a single-node Squid cluster (Ubuntu 22.04 aarch64, Node 24.22.3, librados 19.2.7):

  • on main, the test aborts the process with the error above;
  • on this branch, the full unit and integration suite passes (9/9), and the build has no warnings with -Wall -Wextra -Wpedantic.

🤖 Generated with Claude Code

Synchronous methods call HandleState::use() on the main thread, which
throws std::runtime_error once the handle is closed. node-addon-api only
converts Napi::Error, so the exception escaped and the process aborted
with SIGABRT. Defining NODE_ADDON_API_CPP_EXCEPTIONS_ALL converts any
std::exception into a JavaScript Error, the same "resource is closed"
error the async methods already reject with.

Fixes #7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexanderSlaa
AlexanderSlaa force-pushed the fix/closed-handle-abort branch from d64bbaa to 7c14f9c Compare November 21, 2026 22:12
@AlexanderSlaa
AlexanderSlaa merged commit 0ac40c9 into main Nov 21, 2026
13 checks passed
@AlexanderSlaa
AlexanderSlaa deleted the fix/closed-handle-abort branch November 21, 2026 22:15
github-actions Bot pushed a commit that referenced this pull request Nov 21, 2026
## [1.2.1](v1.2.0...v1.2.1) (2026-11-21)

### Bug Fixes

* **native:** throw instead of aborting on calls to a closed handle ([#10](#10)) ([0ac40c9](0ac40c9)), closes [#7](#7)
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process aborts on synchronous calls to a closed Cluster or IoContext

1 participant