From 015692d51eeeb39cce0a7cb6549bcea30b59406d Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 26 Apr 2026 11:30:22 +0200 Subject: [PATCH] Tear down active and pending links before interface detach --- RNS/Link.py | 4 ++-- RNS/Transport.py | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index e7bef23..451fcbf 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -1319,11 +1319,11 @@ class Link: def cancel_outgoing_resource(self, resource): if resource in self.outgoing_resources: self.outgoing_resources.remove(resource) - else: RNS.log("Attempt to cancel a non-existing outgoing resource", RNS.LOG_ERROR) + else: RNS.log("Attempt to cancel a non-existing outgoing resource", RNS.LOG_WARNING) def cancel_incoming_resource(self, resource): if resource in self.incoming_resources: self.incoming_resources.remove(resource) - else: RNS.log("Attempt to cancel a non-existing incoming resource", RNS.LOG_ERROR) + else: RNS.log("Attempt to cancel a non-existing incoming resource", RNS.LOG_WARNING) def ready_for_new_resource(self): if len(self.outgoing_resources) > 0: return False diff --git a/RNS/Transport.py b/RNS/Transport.py index dce090e..05f2dac 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -2998,25 +2998,31 @@ class Transport: @staticmethod def detach_interfaces(): + with Transport.active_links_lock: + for link in Transport.active_links: + try: link.teardown() + except Exception as e: RNS.log(f"Could not tear down active link before interface detach: {e}", RNS.LOG_WARNING) + + with Transport.pending_links_lock: + for link in Transport.pending_links: + try: link.teardown() + except Exception as e: RNS.log(f"Could not tear down pending link before interface detach: {e}", RNS.LOG_WARNING) + detachable_interfaces = [] for interface in Transport.interfaces: # Currently no rules are being applied # here, and all interfaces will be sent # the detach call on RNS teardown. - if not interface.detached: - detachable_interfaces.append(interface) - else: - pass + if not interface.detached: detachable_interfaces.append(interface) + else: pass for interface in Transport.local_client_interfaces: # Currently no rules are being applied # here, and all interfaces will be sent # the detach call on RNS teardown. - if not interface.detached: - detachable_interfaces.append(interface) - else: - pass + if not interface.detached: detachable_interfaces.append(interface) + else: pass shared_instance_master = None local_interfaces = []