Repository navigation
fix(native): throw instead of aborting on calls to a closed handle - #10
Merged
Merged
Conversation
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
force-pushed
the
fix/closed-handle-abort
branch
from
November 21, 2026 22:12
d64bbaa to
7c14f9c
Compare
|
🎉 This PR is included in version 1.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
Problem
Synchronous methods call
HandleState::use()on the main thread, which throwsstd::runtime_error("resource is closed")once the handle is closed. node-addon-api only convertsNapi::Errorinto a JavaScript exception, so thestd::runtime_errorescaped and the process aborted with SIGABRT:Affected:
IoContext.setNamespace(),setLocatorKey(),setReadSnapshot(),poolId,lastVersionandCluster.config(),instanceId,ioContext()on a closed handle.Fix
Define
NODE_ADDON_API_CPP_EXCEPTIONS_ALLinbinding.gypandCMakeLists.txt. node-addon-api then converts anystd::exceptionthrown from a callback into a JavaScriptErrorwith its message. Calls on a closed handle now throwError: resource is closed, the same error the async methods already reject with. It also covers any otherstd::exception(such asstd::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):
main, the test aborts the process with the error above;-Wall -Wextra -Wpedantic.🤖 Generated with Claude Code