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] Unify subscription lifecycle and guard node/context teardown - #1707
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>
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
Observable subscriptions follow node-owned ROS cleanup. Node and Context maintain independent lifecycle states with shared definitions, safe teardown coordination, and retryable cleanup.
Changes
Fix: #1706