Repository navigation
fix(libre3): make scheduleReconnect idempotent to stop a reconnect storm - #3
Merged
Merged
Conversation
The permanent-wedge fix routed transient handshake errors to scheduleReconnect(), but that re-entered itself: scheduleReconnect()'s own gatt.disconnect() fires onConnectionStateChange(DISCONNECTED), which calls scheduleReconnect() again, and repeated error frames do the same. With no guard, each call started another connectGatt. Observed live 2026-11-20: a glitch produced 312 status=147 disconnects across overlapping GATT connections over ~15 min (no BG the whole time) before exponential backoff throttled it. It self-recovered — unlike the old wedge — but hammered the radio and dragged recovery out. Add a `reconnectScheduled` guard so only one reconnect is ever in flight, collapsing the storm to a single orderly retry. Also close any existing gatt at the top of openGatt() as a belt-and-suspenders against leaks, and reset the flag on connect()/disconnect(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
The permanent-wedge fix (db6e5fe) routed transient handshake errors to
scheduleReconnect()instead ofdisconnect(). That is re-entrant:scheduleReconnect()callsgatt.disconnect(), whose asynconConnectionStateChange(DISCONNECTED)callback also callsscheduleReconnect(), and repeated error frames do the same. With no guard, each call started anotherconnectGatt.Observed live 2026-11-20: a single glitch produced 312
status=147disconnects across overlapping GATT connections over ~15 min with no BG, until exponential backoff throttled it. It self-recovered (unlike the old wedge) but hammered the shared BLE radio and dragged recovery out to ~15 min instead of seconds. Pump link was unaffected.Fix
reconnectScheduledguard so only one reconnect is ever in flight; re-entrant and repeated calls become no-ops. The storm collapses to a single orderly retry on backoff.gattat the top ofopenGatt()(belt-and-suspenders against a leaked client — exactly what turned one glitch into a storm).connect()/disconnect().Testing
:libre3:compileFullDebugKotlin+:libre3:testFullDebugUnitTestpass.loopAPK and installed live (3.4.2.3-hovorka-reconnstorm): loop looping, BG flowing, normal reconnect cycle clean, 0×status=147bursts.Libre3BleClientextendsBluetoothGattCallback, no Robolectric in the module. The storm-path single-retry is structurally guaranteed but will only be observed on the next real glitch.🤖 Generated with Claude Code