Skip to content

Commit d8c2353

Browse files
1technophileclaude
andcommitted
Fix race condition in BM2 notification handling
Apply the same race condition fix to BM2 that was applied to BM6. Set m_taskHandle before calling subscribe() to ensure the callback can properly use the task handle even if notifications arrive immediately. Changes: - Set m_taskHandle before subscribe() instead of after - Clear m_taskHandle on subscription failure - Matches pattern now used in BM6 This prevents the callback from exiting early due to m_taskHandle being nullptr when notifications arrive very quickly after subscription. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3bba55d commit d8c2353

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

main/gatewayBLEConnect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,15 @@ void BM2_connect::publishData() {
319319

320320
if (pChar && pChar->canNotify()) {
321321
THEENGS_LOG_TRACE(F("Registering notification" CR));
322+
m_taskHandle = xTaskGetCurrentTaskHandle();
322323
if (pChar->subscribe(true, std::bind(&BM2_connect::notifyCB, this,
323324
std::placeholders::_1, std::placeholders::_2,
324325
std::placeholders::_3, std::placeholders::_4))) {
325-
m_taskHandle = xTaskGetCurrentTaskHandle();
326326
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(BLE_CNCT_TIMEOUT)) == pdFALSE) {
327327
m_taskHandle = nullptr;
328328
}
329329
} else {
330+
m_taskHandle = nullptr;
330331
THEENGS_LOG_NOTICE(F("Failed registering notification" CR));
331332
}
332333
}

0 commit comments

Comments
 (0)