fix: make magic peripheral handoff resilient (+ consistency cleanups)#56
Closed
MegaManSec wants to merge 2 commits into
Closed
fix: make magic peripheral handoff resilient (+ consistency cleanups)#56MegaManSec wants to merge 2 commits into
MegaManSec wants to merge 2 commits into
Conversation
Follow-up cleanups on the cherry-picked handoff-resilience fix so the new code matches the surrounding conventions. No behavior change. - Extract the duplicated `75` body-timeout literal (CONNECT_ALL / CONNECT_ONE) into a named `NetworkDeviceStore.handoffBodyTimeout`, and document the cross-file invariant: it must exceed the receiver's pair watchdog (60s) and stay <= IncomingConnection.idleTimeout, so neither side gives up before the receiver acks the real connect result. - Explain on IncomingConnection.idleTimeout why it was raised 30s -> 75s. - Add a rationale comment to the post-`-remove` Thread.sleep: it lets the async unbond settle, and only stalls the background bluetoothQueue, never the UI.
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.
Summary
Cherry-picks upstream
iFurySt/magic-switch@270c1e5("fix: make magic peripheral handoff resilient"), original author preserved, plus follow-up cleanups so the new code matches this repo's conventions.What the upstream fix does
paired=truewhileopenConnection()fails; the old path gave up and left it connectable on neither Mac. It now-removes the stale bond and re-pairs.CONNECT_ALL/CONNECT_ONEreceivers ack the real connect result instead of "command received", so a failed handoff is actually rolled back / reclaimed by the sender.Cleanups in this PR (2nd commit — no behavior change)
75body-timeout literal into a namedNetworkDeviceStore.handoffBodyTimeout, documenting the cross-file invariant (must exceed the 60s pair watchdog and stay<=IncomingConnection.idleTimeout).idleTimeoutwas raised 30s -> 75s.-removeThread.sleep(settles the async unbond; only blocks the backgroundbluetoothQueue, never the UI).Cherry-pick adaptations (folded into the 1st commit)
BluetoothPeripheralStore: this fork hoistedreconnectInFlight.remove(id)to the top ofreclaimIfPeerIsFree's else-block, so I dropped upstream's duplicate and kept the newconnectPeripheral(...)signature.continueAdoption(this fork's "adopt when the peer vanishes" feature, which upstream never saw) called the now-removed 2-argconnectPeripheral. Adapted to the new signature withrefreshPairingBeforeConnect: false, preserving current behavior.Open question
continueAdoptionis itself a take-from-peer path, so arguably it should passrefreshPairingBeforeConnect: trueto get the same stale-pairing fix. Leftfalseto avoid changing behavior beyond the cherry-pick — say the word to flip it.Verification
xcodebuild -scheme "Magic Switch" -configuration Debug-> BUILD SUCCEEDED.