From e0aa46ba22fe2490cb0173a2f9a5dda648bf4532 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 18 Apr 2026 14:50:45 +0200 Subject: [PATCH] Improved gracious transport data persist handling --- RNS/Interfaces/LocalInterface.py | 3 ++- RNS/Reticulum.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RNS/Interfaces/LocalInterface.py b/RNS/Interfaces/LocalInterface.py index 4b069c8..629ed50 100644 --- a/RNS/Interfaces/LocalInterface.py +++ b/RNS/Interfaces/LocalInterface.py @@ -328,7 +328,8 @@ class LocalClientInterface(Interface): if hasattr(self, "parent_interface") and self.parent_interface != None: self.parent_interface.clients -= 1 if hasattr(RNS.Transport, "owner") and RNS.Transport.owner != None: - RNS.Transport.owner._should_persist_data() + background = not self.detached + RNS.Transport.owner._should_persist_data(background=background) if nowarning == False: RNS.log("The interface "+str(self)+" experienced an unrecoverable error and is being torn down. Restart Reticulum to attempt to open this interface again.", RNS.LOG_ERROR) diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 29034bb..c05ea1d 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -47,6 +47,7 @@ else: from RNS.Interfaces import * from RNS.vendor.configobj import ConfigObj +from threading import Lock import configparser import multiprocessing.connection import importlib.util @@ -171,6 +172,8 @@ class Reticulum: cachepath = "" interfacepath = "" + gracious_persist_lock = Lock() + __instance = None __interface_detach_ran = False @@ -995,12 +998,15 @@ class Reticulum: def _should_persist_data(self, background=False): if time.time() > self.last_data_persist+Reticulum.GRACIOUS_PERSIST_INTERVAL: - self.__persist_data(background=background) + def job(): self.__persist_data(background=background) + threading.Thread(target=job, daemon=True).start() def __persist_data(self, background=False): - RNS.Transport.persist_data(background=background) - RNS.Identity.persist_data(background=background) - self.last_data_persist = time.time() + if Reticulum.gracious_persist_lock.locked(): return + with Reticulum.gracious_persist_lock: + RNS.Transport.persist_data(background=background) + RNS.Identity.persist_data(background=background) + self.last_data_persist = time.time() def __clean_caches(self, background=False): RNS.log("Cleaning resource and packet caches...", RNS.LOG_EXTREME)