Skip to content

[refactor] Unify subscription lifecycle and guard node/context teardown - #1707

Open
minggangw wants to merge 8 commits into
RobotWebTools:developfrom
minggangw:fix-1706
Open

minggangw wants to merge 8 commits into
RobotWebTools:developfrom
minggangw:fix-1706

Conversation

@minggangw

@minggangw minggangw commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

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

  • Observable completion and destroyed state reflect underlying subscription or node destruction.
  • In-progress or completed teardown rejects entity creation and spin requests.
  • Native context shutdown waits for registered nodes to finish teardown.
  • Failed handle synchronization preserves entity and QoS-event registrations for later cleanup.
  • Shared lifecycle guards validate resource creation before native allocation, including after QoS callbacks and in action constructors.
  • Regression coverage verifies automatic completion, reentrant shutdown, allocation rejection, and cleanup retries.
  • Public type signatures remain unchanged.

Fix: #1706

Copilot AI balanced review requested due to automatic review settings November 28, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Review effort: Balanced

@coveralls

coveralls commented Nov 28, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 91.508% (+0.2%) from 91.357% — minggangw:fix-1706 into RobotWebTools:develop

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

Comment thread lib/node.js Outdated
if (this.spinning) {
this.stop();
}
if (this._destroying) return;

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

High severity 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).

Medium severity 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 minggangw changed the title [refactor] Align observable subscriptions with node entity lifecycle [refactor] Unify subscription lifecycle and guard node/context teardown Nov 30, 2026
minggangw and others added 8 commits November 30, 2026 18:38
Reject creation and dispatch during teardown, preserve cleanup retries, and cover generic finalizer reentrancy independently of observable subscriptions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor observable subscriptions

3 participants