Fix BLE advertising management to prevent crashes during reconnections#10658
Fix BLE advertising management to prevent crashes during reconnections#10658thebentern wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent ESP32 NimBLE crashes during BLE reconnections (notably when a phone reconnects with a stale bond after the device’s NVS/bond store has been wiped) by deferring advertising restart out of the NimBLE disconnect callback and by tightening when the code latches an authenticated/connected state.
Changes:
- Defer BLE advertising restart from
onDisconnect()into the main task’srunOnce(), gated byble_hs_synced()to avoid re-entering GAP APIs during host reset. - Add an encryption-state guard in
onAuthenticationComplete()to avoid treating failed encryption changes as a successful authenticated connection.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Firmware Size Report21 targets | vs
Show 16 more target(s)
Updated for 80f33ed |
cpatulea
left a comment
There was a problem hiding this comment.
Yowch, what a mess. Looks reasonable. Have not tested on a device.
|
|
||
| nimbleBluetoothConnHandle = BLE_HS_CONN_HANDLE_NONE; | ||
|
|
||
| ble->startAdvertising(); |
There was a problem hiding this comment.
Looks like Arduino-ESP32's native 'advertiseOnDisconnect' does make this call directly from the callback, like us: https://github.com/espressif/arduino-esp32/blob/0d1440d1be38ab530d274fe87ee88565fe167392/libraries/BLE/src/BLEServer.cpp#L588
@lucasssvaz in case he has any comment
⚡ Try this PR in the Web FlasherWarning This is an automated, unreviewed CI test build. Back up your device configuration Supported boards built by this PR (21)
Build artifacts expire on 2026-07-10. Updated for |
@vidplace7 give this a test run