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 <noreply@anthropic.com>
This commit is contained in:
parent
572204557e
commit
1e1023f914
1 changed files with 6 additions and 0 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue