You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[refactor] Align observable ownership and guard teardown reentrancy - #1707
Align observable subscriptions with node-owned cleanup and coordinate reentrant Node/Context teardown using distinct teardown states.
Changes
Tie observable completion and destroyed state to the underlying subscription, including node-owned cleanup and explicit destruction retries.
Define separate NodeTeardownState and ContextTeardownState enums in lib/teardown_states.js, with independent _teardownState fields and owner-specific state semantics.
Ignore reentrant teardown calls and reject entity creation and spinning during or after teardown.
Defer native Context shutdown until registered nodes finish cleanup, retaining failed node teardown for retry.
Recheck entity creation immediately before native allocation after QoS validation, type metadata, and content-filter conversion callbacks.
Apply allocation guards to direct action constructors and lifecycle publishers.
Use non-private names for cross-class coordination methods and document shutdown guards with compact call stacks.
Add regression coverage for ownership, completion ordering, reentrancy, deferred shutdown, allocation rejection, and cleanup retries.
Use same-sandbox Sinon spies for call-order assertions and preserve native startup-failure coverage.
Update lifecycle documentation without changing public TypeScript signatures, and remove the unused action-goal cancellation flag.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Completion callbacks now run synchronously during native-backed teardown, while tests cover only wrapper/subscription reentrancy, leaving node/context shutdown reentrancy needing human review and ROS runtime validation.
No open issues 🎉
What changed in this PR
Aligns RxJS observable subscriptions with rclnodejs’s node-owned entity lifecycle, so observable completion and destroyed state follow the underlying ROS 2 subscription.
Changes:
Adds a subscription subclass that completes its observable during entity finalization.
Shares subscription creation logic while preserving node registration and delegating wrapper destruction to the node.
Adds lifecycle regression tests and documents teardown, retry, and unsubscribe behavior.
File
Description
types/observable_subscription.d.ts
Documents ownership, destroyed state, and completion semantics.
types/node.d.ts
Documents observable completion on subscription or node destruction.
test/test-observable-subscription.js
Adds registration, teardown, finalization, and destruction-retry coverage.
lib/subscription.js
Allows the subscription factory to instantiate subclasses.
lib/observable_subscription.js
Moves observable ownership into the subscription entity and delegates wrapper lifecycle operations.
lib/node.js
Extracts shared creation logic and registers observable subscription entities.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical teardown race allows context shutdown to finalize native resources before in-progress node destruction finishes; the teardown paths need coordination and a regression test.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Lifecycle checks occur too late to prevent native allocation with released handles, and failed subscription destruction loses cleanup ownership, leaving finalizers skipped during bulk teardown.
Lifecycle state is not rechecked before native allocation
lib/node.js:649
The registration guard runs after native allocation: a QoS validation callback that destroys the node or shuts down its context lets publisher/subscription creation continue with a released handle. Direct ActionClient/ActionServer construction also allocates before this guard. Recheck lifecycle state after QoS callbacks and before allocation (lib/node.js:909,1042), and add pre-allocation checks to the action constructors (lib/action/client.js:102, lib/action/server.js:120).
Failed subscription destruction is lost from bulk teardown
lib/node.js:1286
If obsSub.destroy() throws from syncHandles(), the registry has already removed the subscription. A later node.destroy() or context.shutdown() skips its finalizer, leaving obsSub.isDestroyed false and its observable uncompleted even after native teardown. Retain failed destructions and their attached events in a pending-cleanup collection, or restore ownership on synchronization failure, so bulk teardown still finalizes them.
Review effort: Balanced
minggangw
changed the title
[refactor] Align observable subscriptions with node entity lifecycle
[refactor] Unify subscription lifecycle and guard node/context teardown
Nov 30, 2026
Keep the node's owning context live while forcing real native startup failure through an uninitialized context. Verify failed starts preserve stopped state and can recover without weakening teardown guards.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Entity creation can still pass a released node handle to native allocation, and failed subscription cleanup removes registrations needed for teardown retries.
minggangw
changed the title
[refactor] Unify subscription lifecycle and guard node/context teardown
[refactor] Align observable ownership and guard teardown reentrancy
Dec 1, 2026
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because critical lifecycle edge cases can leave failed cleanup incomplete across retries or allow native entity allocation after node teardown.
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
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.
Summary
Align observable subscriptions with node-owned cleanup and coordinate reentrant Node/Context teardown using distinct teardown states.
Changes
Fixes #1706