From fe0dcac90ff890be5abaaab87ce8e7cbd22056f9 Mon Sep 17 00:00:00 2001 From: Matthew Wolter Date: Sat, 11 Apr 2026 20:24:24 -0700 Subject: [PATCH] =?UTF-8?q?G4:=20F16=20=E2=80=94=20re-register=20disconnec?= =?UTF-8?q?t=20callback=20after=20BLE=20client=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: handle_disconnect resets self.client to self._user_provided_client. That client's disconnected_callback was not re-registered, so subsequent BLE disconnects after a successful reconnect cycle were missed — ConnectionManager never learned the link dropped again. Now re-registers via set_disconnected_callback with a hasattr guard and try/except for bleak version compatibility. The next connect() call would also re-create the client with the callback, but this closes the gap between disconnect and reconnect. Refs: Forensics report finding F16 --- src/meshcore/ble_cx.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/meshcore/ble_cx.py b/src/meshcore/ble_cx.py index f1213c2..afe9dfb 100644 --- a/src/meshcore/ble_cx.py +++ b/src/meshcore/ble_cx.py @@ -154,6 +154,17 @@ class BLEConnection: self.client = self._user_provided_client self.device = self._user_provided_device + # Re-register disconnect callback on the reset client so subsequent + # disconnects after a reconnect cycle are still detected. + if self.client is not None and hasattr(self.client, 'set_disconnected_callback'): + try: + self.client.set_disconnected_callback(self.handle_disconnect) + except Exception: + # set_disconnected_callback may not be available on all bleak + # versions; the next connect() call will re-create the client + # with the callback anyway. + pass + if self._disconnect_callback: asyncio.create_task(self._disconnect_callback("ble_disconnect"))