From 55d8171ad89a668a04aaab905efa320ac0e8b9b1 Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Mon, 6 Jul 2026 16:06:44 +0800 Subject: [PATCH] Fix race condition in PeriodicAdvertisingSync state transition In PeriodicAdvertisingSync.establish, the state was unconditionally set to PENDING after sending the create sync command. If the sync was established immediately (e.g. HCI_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_EVENT received before establish completed), the state transition to ESTABLISHED would be overwritten back to PENDING, causing timeouts in listeners waiting for establishment. Only set state to PENDING if it is still INIT. TAG=agy CONV=e61bef8b-ae31-48da-9bac-74f55d92568d --- bumble/device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bumble/device.py b/bumble/device.py index e90dbf01..9450533b 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -913,7 +913,8 @@ async def establish(self) -> None: ) ) - self.state = self.State.PENDING + if self.state == self.State.INIT: + self.state = self.State.PENDING async def terminate(self) -> None: if self.state in (self.State.INIT, self.State.CANCELLED, self.State.TERMINATED):