fix(api-gateway): prevent rmb peer from wedging on failed (re)creation#2698
Merged
Conversation
Extract peer creation into spawnPeer(), which binds each peer to a fresh child context and retries NewPeer *without* cancelling that context on failure. Both retry blocks previously created currentPeerCtx once and cancel()-ed it inside the retry on error. NewPeer starts its background goroutines only after all of its error paths, so a failed attempt has nothing to clean up while cancelling poisons the shared context: every subsequent retry (and the eventual live peer) then ran on an already-cancelled context and never received rmb calls until a manual restart. Also unify the in-memory expiration to 6h on both the initial and the config-update reconnect paths (the reconnect path used 6*60 = 6 minutes with a misleading "1 hours" comment), and give each spawn its own backoff instead of sharing one instance across both paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ashraffouda
requested review from
AhmedHanafy725,
Eslam-Nawara,
Omarabdul3ziz,
rawdaGastan,
sameh-farouk and
xmonader
as code owners
July 22, 2026 13:15
sameh-farouk
approved these changes
Jul 22, 2026
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.
Extract peer creation into spawnPeer(), which binds each peer to a fresh child context and retries NewPeer without cancelling that context on failure.
Both retry blocks previously created currentPeerCtx once and cancel()-ed it inside the retry on error. NewPeer starts its background goroutines only after all of its error paths, so a failed attempt has nothing to clean up while cancelling poisons the shared context: every subsequent retry (and the eventual live peer) then ran on an already-cancelled context and never received rmb calls until a manual restart.
Also unify the in-memory expiration to 6h on both the initial and the config-update reconnect paths (the reconnect path used 6*60 = 6 minutes with a misleading "1 hours" comment), and give each spawn its own backoff instead of sharing one instance across both paths.
Description
Describe the changes introduced by this PR and what does it affect
Changes
List of changes this PR includes
Related Issues
List of related issues
Checklist
Closes #2697