Skip to content

Commit 15b1705

Browse files
lucasssvazCopilot
andauthored
Update libraries/BLE/src/BLECharacteristic.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6fcf0e7 commit 15b1705

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,22 @@ int BLECharacteristic::handleGATTServerEvent(uint16_t conn_handle, uint16_t attr
958958
pCharacteristic->setValue(buf, len);
959959

960960
// Call the onWrite callback before returning.
961-
// This ensures that when the client receives the acknowledgment, the write has been processed.
962-
// NimBLE sends the response automatically based on the return code of this function.
961+
// NOTE: This callback is executed synchronously in the NimBLE GATT access context.
962+
// NimBLE sends the write response automatically after this function returns,
963+
// based on its return code. As a result, any work performed in onWrite()
964+
// directly impacts when the client receives the ATT write acknowledgment.
965+
//
966+
// Behavioral change:
967+
// In earlier implementations that used a deferred callback mechanism, the write
968+
// response was sent before the onWrite() callback executed. Applications that
969+
// relied on that behavior (e.g., long-running or blocking onWrite() handlers,
970+
// or handlers that perform notify/indicate operations) may now experience
971+
// delayed write acknowledgments if onWrite() takes significant time to complete.
972+
//
973+
// Recommendation:
974+
// Implement onWrite() as a fast, non-blocking callback. Offload long-running
975+
// processing to another task or queue to avoid increasing write latency or
976+
// causing client timeouts.
963977
pCharacteristic->m_pCallbacks->onWrite(pCharacteristic, &desc);
964978

965979
return 0;

0 commit comments

Comments
 (0)