Repository navigation
Conversation
MaxRink
force-pushed
the
collision-close-loser-at-open
branch
from
October 30, 2026 15:00
5703fa0 to
881cc87
Compare
MaxRink
marked this pull request as ready for review
October 30, 2026 15:00
This was referenced Oct 30, 2026
MaxRink
force-pushed
the
collision-close-loser-at-open
branch
2 times, most recently
from
December 2, 2026 01:42
d1ab39e to
80dbe27
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The connection tracker resets the OpenSent hold timer instead of preserving its expiry, potentially keeping a silent incoming connection open for nearly twice the intended timeout.
1 open issue
What changed in this PR
Delays closing a losing incoming BGP connection until the peer’s first message arrives, addressing the FRR reconnection and extra session drop described in #3863.
Changes:
- Transfers the losing connection’s reader to a background handler.
- Makes shared parsing flags atomic.
- Adds collision-response and cleanup tests and updates existing expectations.
| File | Description |
|---|---|
| pkg/server/fsm.go | Defers collision-loser closure and synchronizes shared flags. |
| pkg/server/fsm_test.go | Updates atomic flag assignments and collision timing expectations. |
| pkg/server/collision_test.go | Tests delayed closure, message responses, and connection cleanup. |
Review effort: Balanced
Since b841cb7, when the peer's OPEN arrives on our outgoing connection while the incoming connection is in OpenSent and has no OPEN yet, and we have the higher BGP Identifier, opensent() sends Cease/Connection Collision Resolution on the incoming connection at once and closes it. RFC 4271 Section 6.8 detects a collision when an OPEN arrives: Upon receipt of an OPEN message, the local system MUST examine all of its connections that are in the OpenConfirm state. The peer has not sent its OPEN on that connection yet, so it does not see the close as the losing side of a collision. FRR connects again. With graceful restart negotiated, the new connection arrives while the session on our connection is Established and is handled as a restart of the peer (RFC 4724 Section 4.2), so the session goes down a second time. In a lab with FRR 10.x, every carrier fault caused two session drops instead of one (confirmed with packet captures). Keep the losing incoming connection open until the peer's first message arrives on it. trackCollisionLoser takes over its recv goroutine, so a message that is partly read is not cut, and answers that message as OpenSent does (RFC 4271 Section 8.2.2): the message error, the OPEN Message Error, the FSM Error, no answer to a version error, but a valid OPEN gets Cease/Connection Collision Resolution. The BGP Identifiers were compared at the OPEN on our connection; both OPENs of a real peer carry the same one. What it sends is not counted for the session, which runs on the other connection; the message it receives is still counted in the session's received message counters, as recvMessageWithError() counts every message it reads. The connection is also closed when the peer closes it, when its OpenSent hold timer expires and when the handler stops. The hold timer is the one opensent() started for the connection; it is not restarted at the collision. twoByteAsTrans and isTreatAsWithdraw become atomic: the recv goroutine of the losing connection outlives OpenSent and reads them in recvMessageWithError, while stateChange() writes them under fsm.lock on the way to Established. TestFSMHandlerOpensent_OutgoingOpenFirst now expects the Cease on the incoming connection after the peer's OPEN on it. Fixes osrg#3863 Signed-off-by: Maximilian Rink <maximilian.rink@telekom.de> Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
MaxRink
force-pushed
the
collision-close-loser-at-open
branch
from
December 2, 2026 15:51
80dbe27 to
c591236
Compare
This branch has not been deployed
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.

Since b841cb7, when the peer's OPEN arrives on our outgoing connection
while the incoming connection is in OpenSent and has no OPEN yet, and we
have the higher BGP Identifier, opensent() sends Cease/Connection
Collision Resolution on the incoming connection at once and closes it.
RFC 4271 Section 6.8 detects a collision when an OPEN arrives:
Upon receipt of an OPEN message, the local system MUST examine all of
its connections that are in the OpenConfirm state.
The peer has not sent its OPEN on that connection yet, so it does not
see the close as the losing side of a collision. FRR connects again.
With graceful restart negotiated, the new connection arrives while the
session on our connection is Established and is handled as a restart of
the peer (RFC 4724 Section 4.2), so the session goes down a second time.
In a lab with FRR 10.x, every carrier fault caused two session drops
instead of one (confirmed with packet captures).
Keep the losing incoming connection open until the peer's first message
arrives on it. trackCollisionLoser takes over its recv goroutine, so a
message that is partly read is not cut, and answers that message as
OpenSent does (RFC 4271 Section 8.2.2): the message error, the OPEN
Message Error, the FSM Error, no answer to a version error, but a valid
OPEN gets Cease/Connection Collision Resolution. The BGP Identifiers
were compared at the OPEN on our connection; both OPENs of a real peer
carry the same one. What it sends is not counted for the session, which
runs on the other connection; the message it receives is still counted
in the session's received message counters, as recvMessageWithError()
counts every message it reads. The connection is also closed when the
peer closes it, when the OpenSent hold time expires and when the handler
stops.
twoByteAsTrans and isTreatAsWithdraw become atomic: the recv goroutine
of the losing connection outlives OpenSent and reads them in
recvMessageWithError, while stateChange() writes them under fsm.lock on
the way to Established.
TestFSMHandlerOpensent_OutgoingOpenFirst now expects the Cease on the
incoming connection after the peer's OPEN on it.
Fixes #3863
Notes for review:
twoByteAsTransandisTreatAsWithdrawbecameatomic.Bool:stateChange()writes them on the way to Established while the losing connection's reader may read them. The race detector cannot show this through the socket, so there is no test for it.Tests:
collision_test.go(answer to each first message incl. bad peer AS, close only after the OPEN, close when the peer closes, handler stop, hold time; goroutine leaks checked with goleak) fails on master and passes with-race -count=3;TestFSMHandlerOpensent_OutgoingOpenFirstnow expects the Cease after the peer's OPEN. Fourpkg/servertests fail on my machine with and without this change (TestDisableMrt,TestEBGPRouteStuck,TestRTCDeferralTimerRaceCondition,TestTcpAoUpdatePeerWithClosedConnection, macOS).Did you use an AI tool?
Yes. Claude Opus 5.5 helped write and review the change; the commit has an
Assisted-bytrailer. I have reviewed it and can answer questions about it.