From e7f605df335f5d30bb1f534981aa42f95935e8d3 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 16 Sep 2022 12:11:25 +1000 Subject: [PATCH] aioble/device.py: Always create connection._event. If the client disconnects immediately after connection, the irq can be run before the initial connect handler has finished. --- micropython/bluetooth/aioble/aioble/device.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/micropython/bluetooth/aioble/aioble/device.py b/micropython/bluetooth/aioble/aioble/device.py index 265d62157..30a54a4fd 100644 --- a/micropython/bluetooth/aioble/aioble/device.py +++ b/micropython/bluetooth/aioble/aioble/device.py @@ -164,7 +164,7 @@ def __init__(self, device): # This event is fired by the IRQ both for connection and disconnection # and controls the device_task. - self._event = None + self._event = asyncio.ThreadSafeFlag() # If we're waiting for a pending MTU exchange. self._mtu_event = None @@ -207,9 +207,6 @@ async def device_task(self): t._task.cancel() def _run_task(self): - # Event will be already created this if we initiated connection. - self._event = self._event or asyncio.ThreadSafeFlag() - self._task = asyncio.create_task(self.device_task()) async def disconnect(self, timeout_ms=2000):