From 603f709139871012a3ab759e7506f785c5eb470f Mon Sep 17 00:00:00 2001 From: Jeremy O'Brien Date: Sun, 17 May 2026 23:55:10 -0400 Subject: [PATCH] Don't iterate known_destinations directly; it can change during iteration --- RNS/Identity.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/RNS/Identity.py b/RNS/Identity.py index e2d1b6bb..afa1bf76 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -127,13 +127,16 @@ class Identity: :returns: An :ref:`RNS.Identity` instance that can be used to create an outgoing :ref:`RNS.Destination`, or *None* if the destination is unknown. """ if from_identity_hash: - for destination_hash in Identity.known_destinations: - if target_hash == Identity.truncated_hash(Identity.known_destinations[destination_hash][2]): + with Identity.known_destinations_lock: + destination_hashes = list(Identity.known_destinations.keys()) + for destination_hash in destination_hashes: + entry = Identity.known_destinations.get(destination_hash) + if entry is None: continue + if target_hash == Identity.truncated_hash(entry[2]): if not _no_use: RNS.Reticulum.get_instance()._used_destination_data(destination_hash) - identity_data = Identity.known_destinations[destination_hash] identity = Identity(create_keys=False) - identity.load_public_key(identity_data[2]) - identity.app_data = identity_data[3] + identity.load_public_key(entry[2]) + identity.app_data = entry[3] return identity return None @@ -285,8 +288,12 @@ class Identity: def _retain_identity(identity_hash): try: retained = False - for destination_hash in Identity.known_destinations: - if identity_hash == Identity.truncated_hash(Identity.known_destinations[destination_hash][2]): + with Identity.known_destinations_lock: + destination_hashes = list(Identity.known_destinations.keys()) + for destination_hash in destination_hashes: + entry = Identity.known_destinations.get(destination_hash) + if entry is None: continue + if identity_hash == Identity.truncated_hash(entry[2]): if Identity._retain_destination_data(destination_hash): retained = True return retained @@ -302,7 +309,9 @@ class Identity: no_path = 0 retained = 0 never_used = 0 - for destination_hash in Identity.known_destinations: + with Identity.known_destinations_lock: + destination_hashes = list(Identity.known_destinations.keys()) + for destination_hash in destination_hashes: try: if RNS.Transport.has_path(destination_hash): has_path = True else: