Skip to content

Commit d2ea3cc

Browse files
committed
fix: Prevent tearing down live client for stale disconnect events
- Add check to verify disconnect callback matches current client before cleanup - Use getattr with default None to safely access bleak_client attribute - Add debug logging when ignoring stale disconnect events - Prevents accidental shutdown of freshly reconnected sessions when old disconnect events fire
1 parent 3343670 commit d2ea3cc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

meshtastic/ble_interface.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ def _on_ble_disconnect(self, client) -> None:
116116
address = getattr(client, "address", repr(client))
117117
logger.debug(f"BLE client {address} disconnected.")
118118
if self.auto_reconnect:
119-
previous_client = self.client
119+
current_client = self.client
120+
if current_client and getattr(current_client, "bleak_client", None) is not client:
121+
logger.debug("Ignoring disconnect from a stale BLE client instance.")
122+
return
123+
previous_client = current_client
120124
self.client = None
121125
if previous_client:
122126
Thread(

0 commit comments

Comments
 (0)