Skip to content

Commit 6cafc0e

Browse files
committed
aioble/server: Fix _init_capture() guard to match _server_shutdown().
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 3eaf027 commit 6cafc0e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

micropython/bluetooth/aioble/aioble/server.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,21 @@ def write(self, data, send_update=False):
100100
else:
101101
ble.gatts_write(self._value_handle, data, send_update)
102102

103-
# When the a capture-enabled characteristic is created, create the
103+
# When a capture-enabled characteristic is created, create the
104104
# necessary events (if not already created).
105+
# Guard on _capture_task (not _capture_queue) to match _server_shutdown()
106+
# which guards on _capture_task. This ensures partial teardown (task gone
107+
# but queue remains) self-heals instead of silently no-oping.
105108
@staticmethod
106109
def _init_capture():
107-
if hasattr(BaseCharacteristic, "_capture_queue"):
110+
if hasattr(BaseCharacteristic, "_capture_task"):
108111
return
109-
112+
# Clean up any partial state from incomplete shutdown
113+
for attr in ("_capture_queue", "_capture_write_event", "_capture_consumed_event"):
114+
try:
115+
delattr(BaseCharacteristic, attr)
116+
except AttributeError:
117+
pass
110118
BaseCharacteristic._capture_queue = deque((), _WRITE_CAPTURE_QUEUE_LIMIT)
111119
BaseCharacteristic._capture_write_event = asyncio.ThreadSafeFlag()
112120
BaseCharacteristic._capture_consumed_event = asyncio.ThreadSafeFlag()

0 commit comments

Comments
 (0)