Skip to content

Simplify tracking of BLE connection handle & improve thread safety.#10390

Open
cpatulea wants to merge 1 commit into
meshtastic:developfrom
cpatulea:ble-connhandle-2
Open

Simplify tracking of BLE connection handle & improve thread safety.#10390
cpatulea wants to merge 1 commit into
meshtastic:developfrom
cpatulea:ble-connhandle-2

Conversation

@cpatulea
Copy link
Copy Markdown
Contributor

@cpatulea cpatulea commented May 4, 2026

  • Redefine isConnected in terms of nimbleBluetoothConnHandle. isConnected was not safe because BLEServer::getConnectedCount is not thread-safe (BLE: thread unsafe access of BLEServer::m_connectedServersMap espressif/arduino-esp32#12538) while isConnected is called from various threads. Now we can avoid checking bleServer every time before calling isConnected.
  • getRssi: don't try to "populate nimbleBluetoothConnHandle", that requires calling BLEServer::getPeerDevices which is not thread-safe (same issue as above).

The code simplifications are intended to facilitate merging of the pioarduino branch (#9122), which makes many changes to NimBLE code.

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

- Redefine isConnected in terms of nimbleBluetoothConnHandle. isConnected was not safe because BLEServer::getConnectedCount is not thread-safe (espressif/arduino-esp32#12538) while isConnected is called from various threads. Now we can avoid checking bleServer every time before calling isConnected.
- getRssi: don't try to "populate nimbleBluetoothConnHandle", that requires calling BLEServer::getPeerDevices which is not thread-safe (same issue as above).

The code simplifications are intended to facilitate merging of the
pioarduino branch (meshtastic#9122), which
makes many changes to NimBLE code.
@cpatulea
Copy link
Copy Markdown
Contributor Author

cpatulea commented May 4, 2026

This is a second pass at #10265 cc @compumike

@github-actions github-actions Bot added the bugfix Pull request that fixes bugs label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants