fix: harden device connect/disconnect and teardown paths#161
Merged
Conversation
Address four connection-robustness reports: - BLE: map the universal_ble "Peer removed pairing information" error (iOS CBErrorPeerRemovedPairingInformation) to a typed MidiPairingInfoRemovedException, best-effort clearing the stale bond (works on Android; on iOS the user must forget the device) instead of leaking a raw UniversalBleException to the parent app. - Android: make ConnectedDevice.close() resilient to a removed device. Unplugging a connected USB MIDI device threw IOException: EPIPE from inputPort.flush(), which aborted the rest of teardown and escaped the onDeviceRemoved callback, crashing the app. Each teardown step now runs quietly so the disconnection notifications always fire. Closes #158. - Platform interface: stop a passive .devices refresh from collapsing a device's transitional connecting/disconnecting state to disconnected. Closes #159. - Core: eagerly guard the connectionEstablished future so a disconnect that races an in-flight connect can no longer surface as an unhandled async error on PlatformDispatcher.onError. Closes #160. Each fix is covered by a regression test. 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.
Summary
Fixes four connection-robustness reports. Each fix has a regression test.
| Report | Fix |
|––––|—–|
| "Peer removed pairing information" shown in the app | Map the universal_ble error (iOS
CBErrorPeerRemovedPairingInformation) to a typedMidiPairingInfoRemovedException; best-effort clear the stale bond (Android; iOS requires the user to forget the device) instead of leaking a rawUniversalBleException. || #158 Android EPIPE crash on USB unplug |
ConnectedDevice.close()routes each teardown step through a quiet helper, so anIOException: EPIPEfrominputPort.flush()on a dead fd can't abort cleanup or escapeonDeviceRemoved; disconnection notifications always fire. || #159
.devicesclobbers a connecting device |_fromHostDeviceno longer appliesconnectedwhile a device is in a transitionalconnecting/disconnectingstate. || #160 unhandled error disconnecting mid-connect | Eagerly guard the
connectionEstablishedfuture so a disconnect racing an in-flight connect can't leak toPlatformDispatcher.onError. |Closes #158
Closes #159
Closes #160
Testing
flutter testfor the main, platform-interface, and BLE packages:flutter_midi_command_android:testDebugUnitTest(Kotlin)flutter analyzeclean across changed packages