fix(network): close idle peer connections, back off on already connected, lower maxbackoff - #4467
Open
stevenvegt wants to merge 3 commits into
Open
fix(network): close idle peer connections, back off on already connected, lower maxbackoff#4467stevenvegt wants to merge 3 commits into
stevenvegt wants to merge 3 commits into
Conversation
…nected Connections to peers on which no message is received for a configurable period (network.idletimeout, default 2 minutes) are now closed, after which the regular reconnect logic takes over. Peers send gossip and diagnostics messages every few seconds, so a silent connection is dead: a half-open TCP connection or a reverse proxy that kept the stream open after the other side went away. Such connections previously lingered until the proxy or node was restarted, and the peer holding the stale connection rejected every new connection attempt with "already connected". The idle check pauses while a message is being handled, so long-running handling (e.g. a large transaction list during sync) is not mistaken for silence. An "already connected" rejection was treated as a clean disconnect and retried every 1 to 5 seconds, bypassing the backoff. It now goes through the exponential backoff like an authentication failure. To make that decision reliable, openOutboundStreams closes the gRPC client connection and waits for the receive loops to exit before reading the close status, which was previously racing with the stream context cancellation. Assisted-by: AI
The backoff towards an unreachable peer grows by 1.5x per failed attempt, is persisted across restarts and is only reset when the peer's NutsComm address changes. A peer that was unreachable for a few days could therefore go unattempted for up to a day after it came back. One extra TLS handshake per hour per dead peer is a negligible price for recovering within the hour. Assisted-by: AI
stevenvegt
requested review from
Dirklectisch,
JorisHeadease,
gerardsn,
reinkrul and
woutslakhorst
as code owners
September 2, 2026 08:45
Assisted-by: AI
Contributor
0 new issues
|
Contributor
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (7)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Problem
A node kept logging this every few seconds for the same four peers, and never got connected to them:
Two things went wrong at once:
Changes
Idle timeout on connections (
network.idletimeout, default2m,0disables). Peers send gossip and diagnostics every 5 seconds on every stream, so a stream with no incoming message for two minutes is dead. The node now closes it and the regular reconnect logic takes over. Time spent handling a message (a large transaction list during sync, for example) does not count as idle. This works through reverse proxies, unlike gRPC keepalive pings, which proxies answer themselves.Back off on "already connected". The rejection is now handled like an authentication failure: exponential backoff instead of a retry every few seconds. Fixing this exposed a race between the receive loop storing the peer's close status and the stream context cancelling the connection, which also affected the existing
Unauthenticatedpath. The close status is now read only after the gRPC connection is closed and the receive loops have exited.network.maxbackoffdefault lowered from24hto1h. The backoff is persisted across restarts and only reset when a peer's NutsComm address changes, so a peer that was unreachable for a few days could go unattempted for up to a day after it came back.Tests
All new behavior was written test-first. New tests in
connection_test.goandconnection_manager_test.go:Backoff()and notReset()TestDefaultConfigasserts the newmaxbackoffandidletimeoutdefaultsgo test -race ./network/...passes.Operational notes
For deployments behind nginx,
grpc_read_timeoutandgrpc_send_timeoutat their 60s default (not raised to hours) plusso_keepaliveon the listen directive let the proxy drop dead streams on its own as well.