Skip to content

Commit 76893f6

Browse files
committed
pbio/drv/bluetooth: Don't restart observing too often.
This timer was missed in the overhaul of 023d6f6. If a user would call observe in a tight loop when there is nothing to receive, this would repeatedly restart scanning. Since the btstack driver doesn't await most operations, this would lead to a crash eventually.
1 parent cff1933 commit 76893f6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,17 @@ pbio_error_t pbdrv_bluetooth_start_observing(pbdrv_bluetooth_start_observing_cal
385385
static bool observe_restart_requested;
386386

387387
void pbdrv_bluetooth_restart_observing_request(void) {
388+
389+
static pbio_os_timer_t restart_timer;
390+
391+
// Don't request restart too often.
392+
if (observe_restart_requested || !pbio_os_timer_is_expired(&restart_timer)) {
393+
return;
394+
}
395+
396+
// Request restart to be handled on main loop.
388397
observe_restart_requested = true;
398+
pbio_os_timer_set(&restart_timer, 10000);
389399
pbio_os_request_poll();
390400
}
391401

0 commit comments

Comments
 (0)