diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 6560625..73ff132 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -186,13 +186,11 @@ class Reticulum: # out cleanup operations. if not Reticulum.__exit_handler_ran: Reticulum.__exit_handler_ran = True - if not Reticulum.__interface_detach_ran: - RNS.Transport.detach_interfaces() + if not Reticulum.__interface_detach_ran: RNS.Transport.detach_interfaces() RNS.Transport.exit_handler() RNS.Identity.exit_handler() - if RNS.Profiler.ran(): - RNS.Profiler.results() + if RNS.Profiler.ran(): RNS.Profiler.results() RNS.loglevel = -1 diff --git a/RNS/Transport.py b/RNS/Transport.py index 05f2dac..e083eae 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -2998,15 +2998,18 @@ 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) + closed_links = 0 + for link in Transport.active_links.copy(): + try: link.teardown(); closed_links += 1 + 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) + for link in Transport.pending_links.copy(): + try: link.teardown(); closed_links += 1 + except Exception as e: RNS.log(f"Could not tear down pending link before interface detach: {e}", RNS.LOG_WARNING) + + # Provide a 150ms window to allow link teardown + # packets to leave local transport + if closed_links: time.sleep(0.15) detachable_interfaces = []