Repository navigation
Fix connect() with a passed BLE device; always close the transport - #125
Merged
fdlamotte merged 1 commit intoNov 22, 2026
Merged
Conversation
- BLEConnection.connect() with a device never set self.address, and returned it, so after the link came up it returned None and MeshCore.connect() raised "Failed to connect to device". It now takes the address from the client, as the scan branch does. - ConnectionManager.disconnect() closed the transport only when it was marked connected. A link stays open after a connect() that returned None once the transport was up (the above, or "Could not find UART service"), and after handle_disconnect() marked it lost on a failed write. It now always closes it; each transport's disconnect() does nothing on a closed link. DISCONNECTED is still emitted only for a connected link. Part of meshcore-dev#119 (C1, C2).
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.
What was wrong (#119, C1 and C2)
create_ble(device=...)always failed. InBLEConnection.connect, the device branch never setself.address, and the method returnsself.address. So it returnedNoneonce the link was up, andMeshCore.connect()raised "Failed to connect to device". I first saw this with a real radio.ConnectionManager.disconnect()closed the transport only when_is_connectedwas set. Two kinds of link were left open:connect()returnedNoneafter the transport came up (C1, or "Could not find UART service");handle_disconnect()after a failed or timed-out write.What changed
disconnect()always callsself.connection.disconnect(); each transport'sdisconnect()already does nothing on a closed link. DISCONNECTED is still emitted only for a link that was connected.Verified with unit tests in
tests/unit/test_ble_device_and_disconnect.py. They fail on currentmain. The whole suite passes on 3.11 and 3.14.Something I noticed while writing these, not changed here:
EventDispatcher.stop()setsrunning = Falsebeforequeue.join(). With two or more events still queued, the loop exits after the first andjoin()waits for ever. Dispatching two events and then callingstop()hangs it. Happy to send that separately if you'd like.Part of #119.