Skip to content

Fix BLE advertising management to prevent crashes during reconnections#10658

Open
thebentern wants to merge 6 commits into
developfrom
tryfix-nimble-crash
Open

Fix BLE advertising management to prevent crashes during reconnections#10658
thebentern wants to merge 6 commits into
developfrom
tryfix-nimble-crash

Conversation

@thebentern

Copy link
Copy Markdown
Contributor

@vidplace7 give this a test run

@thebentern thebentern requested review from Copilot and vidplace7 June 9, 2026 12:41
@github-actions github-actions Bot added the needs-review Needs human review label Jun 9, 2026
@github-actions github-actions Bot added the bugfix Pull request that fixes bugs label Jun 9, 2026
@thebentern thebentern removed the needs-review Needs human review label Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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’s runOnce(), gated by ble_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.

Comment thread src/nimble/NimbleBluetooth.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Firmware Size Report

21 targets | vs develop: 21 increased, net +41,232 (+40.3 KB)

Target Size vs develop
station-g3 2,210,320 📈 +3,568 (+3.5 KB)
heltec-v3 2,208,880 📈 +3,456 (+3.4 KB)
station-g2 2,218,912 📈 +2,784 (+2.7 KB)
t-eth-elite 2,435,712 📈 +2,608 (+2.5 KB)
seeed-xiao-s3 2,219,024 📈 +2,576 (+2.5 KB)
Show 16 more target(s)
Target Size vs develop
rak3312 2,215,056 📈 +2,544 (+2.5 KB)
t-deck-tft 3,754,576 📈 +2,400 (+2.3 KB)
rak11200 1,804,352 📈 +2,352 (+2.3 KB)
pico2w 1,178,768 📈 +2,060 (+2.0 KB)
picow 1,197,280 📈 +2,040 (+2.0 KB)
seeed_xiao_rp2350 728,392 📈 +1,912 (+1.9 KB)
pico 737,360 📈 +1,896 (+1.9 KB)
pico2 730,232 📈 +1,896 (+1.9 KB)
rak11310 759,944 📈 +1,896 (+1.9 KB)
seeed_xiao_rp2040 735,560 📈 +1,896 (+1.9 KB)
tlora-c6 2,316,352 📈 +1,168 (+1.1 KB)
heltec-ht62-esp32c3-sx1262 2,082,640 📈 +1,120 (+1.1 KB)
elecrow-adv-35-tft 3,362,608 📈 +1,056 (+1.0 KB)
heltec-vision-master-e213-inkhud 2,170,640 📈 +1,056 (+1.0 KB)
wio-e5 232,404 📈 +488
rak3172 180,040 📈 +460

Updated for 80f33ed

@vidplace7 vidplace7 requested a review from cpatulea June 9, 2026 14:08

@cpatulea cpatulea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yowch, what a mess. Looks reasonable. Have not tested on a device.


nimbleBluetoothConnHandle = BLE_HS_CONN_HANDLE_NONE;

ble->startAdvertising();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Flash this PR in the Web Flasher

firmware commit boards expires

Warning

This is an automated, unreviewed CI test build. Back up your device configuration
before flashing, and only flash devices you are able to recover.

Supported boards built by this PR (21)
Device Board Platform
Crowpanel Adv 3.5 TFT elecrow-adv-35-tft esp32-s3
Heltec HT62 heltec-ht62-esp32c3-sx1262 esp32-c3
Heltec Mesh Node 096 heltec-mesh-node-t096 nrf52840
Heltec Mesh Node T1 heltec-mesh-node-t1 nrf52840
Heltec Mesh Node T114 heltec-mesh-node-t114 nrf52840
Heltec V3 heltec-v3 esp32-s3
Raspberry Pi Pico pico rp2040
Raspberry Pi Pico W picow rp2040
RAK WisBlock 11200 rak11200 esp32
RAK WisBlock 11310 rak11310 rp2040
RAK3312 rak3312 esp32-s3
RAK WisBlock 4631 rak4631 nrf52840
Seeed Xiao NRF52840 Kit seeed_xiao_nrf52840_kit nrf52840
Seeed Xiao ESP32-S3 seeed-xiao-s3 esp32-s3
Station G2 station-g2 esp32-s3
Station G3 station-g3 esp32-s3
LILYGO T-Deck t-deck-tft esp32-s3
LILYGO T-Echo t-echo nrf52840
LILYGO T-Echo Plus t-echo-plus nrf52840
LilyGo T3-C6 tlora-c6 esp32-c6
Seeed SenseCAP T1000-E tracker-t1000-e nrf52840

Build artifacts expire on 2026-07-10. Updated for 9297391.

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.

3 participants