fix(network): preserve TCP reconnect backoff on short sessions#5893
Merged
jamesarich merged 2 commits intoJun 21, 2026
Conversation
TcpTransport.connectWithRetry reset the reconnect backoff to the minimum (1 second) whenever any data was received during a session, even if the session lasted only 1-2 seconds before the radio closed the connection (EOF). This is common with ESP32 radios that enter light sleep without a BLE session: the firmware dumps its Stage-1 config, then immediately closes the TCP PhoneAPI session. Treating this as a successful data exchange caused the app to hammer the sleeping radio at ~1 Hz, which prevented the firmware's WiFi/PhoneAPI stack from recovering and eventually made the radio stop responding to new connections entirely. Only reset backoff when the session lasted at least 30 seconds (SHORT_SESSION_THRESHOLD_MS). Short sessions that ended in peer-EOF keep the backoff growing (1s -> 2s -> 4s -> 8s -> ...), giving the radio time to settle between reconnect attempts.
Extract the reconnect-backoff reset logic into a pure internal helper (shouldResetBackoff) so it can be unit-tested without sockets. Covers the four policy boundaries: no data, data below threshold, data at threshold, and data above threshold.
jamesarich
approved these changes
Jun 21, 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.
Overview
This PR fixes TCP reconnect behavior for radios that briefly accept a PhoneAPI TCP connection, send initial/config data, and then close the socket before the session is actually stable. Previously, any received data reset reconnect backoff to the 1-second floor, so repeated short sessions could hammer a sleeping or recovering radio at roughly 1 Hz. The fix only resets reconnect backoff after a data-bearing session has remained connected long enough to be treated as stable.
Key Changes
Fixes
Refactors
SHORT_SESSION_THRESHOLD_MSto document the stable-session cutoff.shouldResetBackoff(...).Testing
ShouldResetBackoffTest.Breaking changes / migration
No breaking API or user-facing migration steps are required. Changes are internal to TCP transport reconnect behavior.