Skip to content

fix(p2p): stop router dialing when context deadline expires - #1588

Merged
lklimek merged 1 commit into
devfrom
fix/router-deadline-shutdown
Nov 6, 2026
Merged

lklimek merged 1 commit into
devfrom
fix/router-deadline-shutdown

Conversation

@lklimek

@lklimek lklimek commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

Stop background connection attempts when a node's time limit expires, preventing an endless busy loop during shutdown.

User story

As a node operator or test author, I want a node started with a time limit to stop its background work when that limit expires.

Scenario

When the time limit expires, background connection attempts currently keep retrying immediately. After this change, they terminate, allowing shutdown to complete without leaving that worker running.

Detailed discussion

Issue being fixed or feature implemented

Investigating the failed test job for #1586 exposed four leaked router dial workers. PeerManager.DialNext returns an empty address and context.DeadlineExceeded; Router.dialPeers handles only context.Canceled, then immediately retries the empty address indefinitely.

This fixes a reproduced leak visible in that dump. The initial TestByzantinePrevoteEquivocation timeout was not reproduced in four focused local runs, so this PR does not claim to resolve every cause of that CI failure.

What was done?

  • Treat context.DeadlineExceeded as terminal alongside context.Canceled before retrying an empty address.
  • Add regressions for canceled and expired contexts and the real router service lifecycle, including worker cleanup.

This is a separate runtime fix based on v1.8-dev. Open PRs #1515 and #1550 leave the deadline retry unchanged. The lifecycle regression also fails on #1515, where joining the worker hangs; applying this same one-line fix to #1515 makes that regression pass.

How Has This Been Tested?

  • Both deadline regressions fail on the unchanged development base.
  • Regressions and existing serial/parallel dialing tests pass with -race -coverprofile, using Go 1.27.3 and the existing native BLS build.
  • Real fix(service)!: join remaining service workers before shutdown completes #1515 lifecycle fails without this fix and passes with this fix, with race detection and coverage enabled.
  • Pinned golangci-lint v2.15.0 on changed lines in ./internal/p2p: zero issues.
  • gofmt and git diff --check pass.

Targeted test selection: TestRouterDialPeersStopsOnContextEnd, TestRouterDeadlineShutdownJoinsWorkers, TestRouter_DialPeers, TestRouter_DialPeers_Parallel. No full-suite rerun was performed.

Breaking Changes

None. No wire, consensus or public API changes.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Co-authored by Claudius the Magnificent AI Agent

PR Hygiene · bc43f40

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Handle deadline expiry before retrying an empty peer address. Cover canceled and expired contexts and shutdown through Router.Start and Wait.

Co-Authored-By: Codex gpt-6-astra <[email protected]>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@thepastaclaw

thepastaclaw commented Nov 4, 2026 •

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit bc43f40) · triage: low

@Claudius-Maginificent Claudius-Maginificent added the priority: high High priority — address soon label Nov 5, 2026
@lklimek
lklimek marked this pull request as ready for review November 5, 2026 10:11

@lklimek lklimek left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/self-reviewed

@lklimek
lklimek enabled auto-merge (squash) November 5, 2026 10:11

@thepastaclaw thepastaclaw 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.

Final validation — Phase 1 + Phase 2

At bc43f40, the change correctly terminates the deadline-driven dialing loop, and the regression tests cover already-ended contexts and service-lifecycle cleanup; no in-scope defects remain. The inspected base-branch change does not supersede the fix, and the supplied drift evidence reports no merge conflicts. Validation was static only: current build, test, vet, lint, security, and end-to-end checks pass; PR Hygiene remains pending.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes a small, contained termination-condition fix in Router.dialPeers and adds focused regression tests without changing protocols or public APIs.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 84% left, weekly 50% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort medium); agent phase2-reviewer
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Separate router shutdown from peer dial-failure accounting — In internal/p2p/router.go:570–595, an in-flight resolution or handshake returning DeadlineExceeded because the router context expired can reach PeerManager.DialFailed. That method ignores context cancellation and persists LastDialFailure and DialFailures, affecting subsequent retry delays and peer scores. This is pre-existing and independent of terminating the DialNext scheduling loop. openConnection only logs handshake failures; it does not call DialFailed.
    • Follow-up: Create a follow-up PR that distinguishes expiration of the parent router context from genuine per-attempt resolution, dial, and handshake timeouts before recording peer failures. Preserve failure accounting for per-attempt timeouts, account for dialPeer returning the generic "all endpoints failed" error, and add focused accounting regressions.

@Claudius-Maginificent Claudius-Maginificent added priority: medium Medium priority and removed priority: high High priority — address soon labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Policy satisfied — this can merge.
Full checklist in the description.

@lklimek
lklimek merged commit 00537e5 into dev Nov 6, 2026
27 checks passed
@lklimek
lklimek deleted the fix/router-deadline-shutdown branch November 6, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: medium Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants