Skip to content

Commit bf5787d

Browse files
authored
Merge pull request #82 from randyscott/fix/ble/smp_notif_race
fix: ble: Race condition in receive for notifications
2 parents 0576bcc + 20baecf commit bf5787d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

smpclient/transport/ble.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,9 @@ async def receive(self) -> bytes:
159159
# self._notify_condition is used to synchronize access to self._buffer.
160160

161161
async with self._notify_condition: # wait for the header
162-
logger.debug(f"Waiting for notify on {SMP_CHARACTERISTIC_UUID=}")
163-
await self._notify_or_disconnect()
164-
165-
if len(self._buffer) < smphdr.Header.SIZE: # pragma: no cover
166-
raise SMPBLETransportException(
167-
f"Buffer contents not big enough for SMP header: {self._buffer=}"
168-
)
162+
while len(self._buffer) < smphdr.Header.SIZE:
163+
logger.debug(f"Waiting for notify on {SMP_CHARACTERISTIC_UUID=}")
164+
await self._notify_or_disconnect()
169165

170166
header: Final = smphdr.Header.loads(self._buffer[: smphdr.Header.SIZE])
171167
logger.debug(f"Received {header=}")

0 commit comments

Comments
 (0)