Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions LibreLoop/Pairing/LibreLoopCGMManager+Pairing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ extension LibreLoopCGMManager {
Task { await delegate?.retractAlert(identifier: id) }
}
self.monitor = monitor
// Session established -- stop any failure-recovery scan armed by the reconnect re-arm.
scanner.stopScan()
self.connectedAt = Date()
// Fresh session: hasn't streamed a reading yet. Drives the
// connect→no-stream livelock accounting in handleMonitorDisconnect.
Expand Down Expand Up @@ -895,13 +897,19 @@ extension LibreLoopCGMManager {
// here too would be a duplicate within ms.
scanner.cancelConnection(peripheral)
} else {
// No active link, no in-flight Task, no CB event
// pending. Explicitly re-arm. scheduleReconnect
// always re-arms the CB connect intent at its top
// (idempotent), and its 0.5s debounce throttles
// Task spawning so this can't tight-loop with the
// events listener's own scheduleReconnect calls.
await MainActor.run { self.scheduleReconnect() }
// No active link, no in-flight Task, no CB event pending. Re-arm the standing connect --
// BUT a bare standing connect can be inert here: a restored-cache handshake failure can leave
// the peripheral .disconnected with iOS silently dropping the pending connect (field log:
// 15-min stall, diagnostic showed peripheral.state=0). The failed ATTEMPT is our error
// evidence, so ALSO engage a scan: it makes iOS actively reacquire the sensor, and a fresh
// discovery re-declares the connect on a fresh handle (.didDiscover) -> a fresh connect.
// Stopped the moment a session is established (see `self.monitor = monitor`).
await MainActor.run {
self.scheduleReconnect()
if self.scanner.centralState == .poweredOn {
self.scanner.startScan()
}
}
}
}
}
Expand Down