Repository navigation
fix(p2p): stop router dialing when context deadline expires - #1588
Conversation
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>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
✅ Final review complete — no blockers (commit bc43f40) · triage: low |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 84% left, weekly 50% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— tenderdash-consensus-security (completed, effort medium); agentphase2-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.
|
Policy satisfied — this can merge. |
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.DialNextreturns an empty address andcontext.DeadlineExceeded;Router.dialPeershandles onlycontext.Canceled, then immediately retries the empty address indefinitely.This fixes a reproduced leak visible in that dump. The initial
TestByzantinePrevoteEquivocationtimeout 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?
context.DeadlineExceededas terminal alongsidecontext.Canceledbefore retrying an empty address.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?
-race -coverprofile, using Go 1.27.3 and the existing native BLS build../internal/p2p: zero issues.gofmtandgit diff --checkpass.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:
For repository code-owners and collaborators only
🤖 Co-authored by Claudius the Magnificent AI Agent
PR Hygiene ·
bc43f40When every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.