Skip to content

Reconnect: on a failed attempt, engage a scan to recover an inert standing connect#3

Open
loopkitdev wants to merge 1 commit into
mainfrom
reconnect-failure-recovery
Open

Reconnect: on a failed attempt, engage a scan to recover an inert standing connect#3
loopkitdev wants to merge 1 commit into
mainfrom
reconnect-failure-recovery

Conversation

@loopkitdev

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2. When a reconnect attempt fails, engage a scan to recover an inert standing connect.

The failure this fixes

The peripheral.state diagnostic added in #2 caught it in the field: after a restored-cache handshake failure (didDisconnect "the specified device has disconnected from us", SensorSessionError error 4), the re-armed standing connect was inert — the peripheral sat .disconnected (peripheral.state=0) with iOS silently dropping the pending connect, and with no fallback it stalled for ~15 minutes until a manual relaunch. Retaining the peripheral (a separate LibreCRKit change) keeps it alive but does not make that standing connect land, so it wasn't sufficient on its own.

Change

In the reconnect re-arm's "disconnected, nothing pending" branch, the failed attempt is treated as the error evidence: alongside re-declaring the standing connect, we now start a scan (guarded on .poweredOn). The scan makes iOS actively reacquire the sensor, and a fresh discovery re-declares the connect on a fresh handle (handleScannerEvent(.didDiscover), from #2) → fresh connect + fresh handshake. The scan is stopped the moment a session is established (self.monitor = monitor).

Targeted — it only runs after a reconnect failure, not the always-on scan we deliberately avoided.

One file, +15/−7. Compile-verified; the reconnect path was exercised on-device alongside #2.

…nding connect

Field log (device-log diagnostic) showed the failure this fixes: after a
restored-cache handshake failure ("device disconnected from us"), the re-armed
standing connect was inert -- the peripheral sat .disconnected (peripheral.state=0)
with iOS silently dropping the pending connect, and with no fallback it stalled
for 15 minutes.

The failed reconnect ATTEMPT is the error evidence, so in the re-arm's
"disconnected, nothing pending" branch we now ALSO start a scan (guarded on
.poweredOn). The scan makes iOS actively reacquire the sensor; a fresh discovery
re-declares the connect on a fresh handle (handleScannerEvent(.didDiscover)),
driving a fresh connect + fresh handshake. The scan is stopped the moment a
session is established. Targeted (only after a failure), not an always-on scan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants