Skip to content

fix(nodes): prevent startup failure when a node is unreachable - #1085

Merged
ImMohammad20000 merged 1 commit into
PasarGuard:devfrom
dr-hoseyn:codex/fix-unreachable-node-startup
Oct 24, 2026
Merged

ImMohammad20000 merged 1 commit into
PasarGuard:devfrom
dr-hoseyn:codex/fix-unreachable-node-startup

Conversation

@dr-hoseyn

@dr-hoseyn dr-hoseyn commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An immediate node connection failure can abort panel startup in v5.5.0: bridge 0.9.4 cancels its lifecycle heartbeat before the task starts, then directly awaiting it replaces the original NodeAPIError with CancelledError.

Drain the heartbeat with asyncio.gather(..., return_exceptions=True) in the shared panel adapter before delegating lifecycle state release to the bridge. Both gRPC and REST retain normal node error handling, and cancellation of the calling task still propagates.

Fixes #1083.

Type of change

  • Bug fix

Checklist

  • I tested the change locally or explained why it cannot be tested.
  • I added or updated tests for behavior changes. (Regression checks were run outside the repository; no test files are included as requested.)
  • I updated documentation, translations, or examples if needed. (Not needed.)
  • I checked database migrations when models or schema changed. (No schema changes.)
  • I did not include secrets, tokens, private keys, or unrelated changes.

Testing

  • Python 3.14.6 with the SHA-256-verified bridge 0.9.4 wheel from the v5.5.0 lockfile.
  • Existing suite: pytest tests/test_node_bridge.py tests/test_node_reconnect_recovery.py tests/test_node_start_timeout.py -q — 65 passed.
  • External regression checks — 8 passed: both transports, heartbeat cancellation before/after task start, lifecycle state/version forwarding, immediate lease reacquisition, missing heartbeat, and genuine caller cancellation.
  • Startup fault injection through the real gRPC client with a socket connection raising OSError(101, "Network is unreachable"): baseline reproduces OSError -> NodeAPIError -> CancelledError; patched startup succeeds and records the node as Error. Delayed failure also remains handled.
  • Ruff lint/format and git diff --check passed.

Screenshots

Not applicable.

Notes for reviewers

Only app/node/bridge.py changes. The adapter works around bridge 0.9.4 cleanup without changing the dependency or suppressing application shutdown cancellation. Validation used controlled transport failures, not a full Docker deployment.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup after batch synchronization, helping ensure background activity is stopped and resources are released when synchronization ends. This reduces the chance of lingering work during shutdown or lifecycle transitions.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7877ed40-d62a-4a86-a5ac-07c0e98a5878
Commits

Reviewing files that changed from the base of the PR and between ef01e1b and cd327e2.

Files selected for processing: 1
  • app/node/bridge.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The queued batch sync now cancels and awaits a lifecycle lease’s heartbeat task before it calls the base lifecycle lease release method with status and version values.

Changes

Lifecycle lease release

Layer / File(s) Summary
Heartbeat cancellation and lease release
app/node/bridge.py
The bridge imports LifecycleLease and LifecycleStatus. Its release override cancels and awaits the heartbeat task, then calls the base release method with the observed and desired statuses and version values.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: drsaeedhub

Merge Risk: Minimal · up to cd327

No actionable merge-blocking risk is identified for this lifecycle-release change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the primary change: preventing startup failure when a configured node is unreachable.
Linked Issues check Passed Issue [#1083] requires an unreachable node to not abort panel startup and to preserve normal node error handling. The PR overrides _release_lifecycle_lease in app/node/bridge.py, cancels and drain…
Out of Scope Changes check Passed The whole-PR diff changes only app/node/bridge.py. The import and _release_lifecycle_lease override directly address the heartbeat cleanup that masks node connection errors. No unrelated productio…
Full details: Linked Issues check

Explanation

Issue [#1083] requires an unreachable node to not abort panel startup and to preserve normal node error handling. The PR overrides _release_lifecycle_lease in app/node/bridge.py, cancels and drains the bridge heartbeat with asyncio.gather(..., return_exceptions=True), then delegates lifecycle release. The reported gRPC fault injection records the affected node as Error, and the reported checks cover both gRPC and REST, delayed failures, and caller cancellation. The reported existing suite passed 65 tests, and eight external regression checks passed.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff changes only app/node/bridge.py. The import and _release_lifecycle_lease override directly address the heartbeat cleanup that masks node connection errors. No unrelated production behavior, dependency change, schema change, or unrelated test change is present.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit watched the heartbeat glow,
Then paused its thump before release.
The lease received its status notes,
Its version values tucked in place.
The carrot queue now rests in peace.

Comment @coderabbitai help to get the list of available commands.

@dr-hoseyn

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ImMohammad20000
ImMohammad20000 merged commit 663a57e into PasarGuard:dev Oct 24, 2026
15 checks passed
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
… does not raise CancelledError

RED on b8e5a6d61 with bridge 0.9.2+singbox: 2 failed, 1 passed (the caller-cancellation guard). Bridge 0.9.2 awaits the cancelled heartbeat directly, the same bug upstream 663a57e (PasarGuard#1085) works around for 0.9.4.
Free-Guy-IR pushed a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
…ard#1085)

(cherry picked from commit 663a57e)

Conflict: the hunk context carried set_reported_versions from 04547de, which the fork has not ported; only the _release_lifecycle_lease override is taken. Valid on bridge 0.9.2+singbox, whose controller.py:371 awaits the cancelled heartbeat directly.
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
…rd#978 and PasarGuard#1085 as ported by their B-NODE cherry-picks and take them off the port queue
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.

2 participants