From 1e1023f914e1265bb1ac9d3bcdcb556afdc799b2 Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Sun, 18 Jan 2026 00:31:56 -0500 Subject: [PATCH] docs: add comment about potential race condition in identity cache Document the narrow race window where data could arrive from an old MAC address before onAddressChanged callback invalidates the cache entry. The window is very small since onAddressChanged fires synchronously during Kotlin deduplication, and _address_changed_callback() cleans up the stale cache entry. Co-Authored-By: Claude Opus 4.5 --- src/ble_reticulum/BLEInterface.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ble_reticulum/BLEInterface.py b/src/ble_reticulum/BLEInterface.py index 781343d..c36df90 100644 --- a/src/ble_reticulum/BLEInterface.py +++ b/src/ble_reticulum/BLEInterface.py @@ -1893,6 +1893,12 @@ class BLEInterface(Interface): if not peer_identity: # Try identity cache - peer may have "disconnected" from Python's view # but Android/driver layer maintains the GATT connection + # + # POTENTIAL RACE CONDITION: If MAC rotation occurred and data arrives from + # the OLD address before onAddressChanged callback fires, we could restore + # a stale mapping here. This is a very narrow window since onAddressChanged + # is invoked synchronously from Kotlin during deduplication. The cache entry + # for the old address gets cleaned up in _address_changed_callback(). cached = self._identity_cache.get(peer_address) if cached and (time.time() - cached[1]) < self._identity_cache_ttl: peer_identity = cached[0]