Fix: onDisconnect not fired when peer powers off with 0x3E disconnect reason#1151
Fix: onDisconnect not fired when peer powers off with 0x3E disconnect reason#1151Copilot wants to merge 2 commits into
onDisconnect not fired when peer powers off with 0x3E disconnect reason#1151Conversation
… after established connection When a BLE connection was established (BLE_GAP_EVENT_CONNECT with status 0) and then disconnects with BLE_ERR_CONN_ESTABLISHMENT (0x3E) - which can happen when the peer powers off within the first 6 connection events - the 2.5.0 retry logic incorrectly suppressed onDisconnect and called onConnectFail after retries (up to 60+ seconds later). Fix: only retry on 0x3E if the connection was never established (m_connStatus != CONNECTED). When the connection was previously established, call onDisconnect (not onConnectFail) so user reconnect logic fires correctly. Agent-Logs-Url: https://github.com/h2zero/NimBLE-Arduino/sessions/ca79e82b-2ceb-4ae8-83d3-c6344ed13cea Co-authored-by: h2zero <32826625+h2zero@users.noreply.github.com>
onDisconnect not fired when peer powers off with 0x3E disconnect reason
|
@copilot how does this address the fact the server device doesn't know about the disconnect? |
The fix addresses the client-side ( Regarding 0x3E after a confirmed connection: looking at the NimBLE controller code ( In 2.4.0, 0x3E called If the peripheral devices are instead running |
In 2.5.0, the connection retry logic for
BLE_ERR_CONN_ESTABLISHMENT(0x3E) incorrectly activates when a previously-established connection drops with that reason code — which happens when the peer powers off within the first 6 connection events (the BLE LL "connection establishment phase"). This suppressesonDisconnectentirely, instead callingonConnectFailafter up to 60+ seconds of retries (2 retries × 30s timeout). Applications with reconnect logic inonDisconnectnever recover.Changes
src/NimBLEClient.cpp— InBLE_GAP_EVENT_DISCONNECT, capturewasConnected = (m_connStatus == CONNECTED)before any state mutation:!wasConnected— i.e., the connection was never confirmed at the host level. A 0x3E on an established connection is a genuine disconnect, not a retryable establishment failure.onDisconnect(notonConnectFail) whenwasConnected && rc == 0x3E, so the semantics match what the application observes: a working connection that went away.isConnectFailflag consistently to thedeleteOnConnectFail/deleteOnDisconnectdeletion logic.