From a496e22ad1c585a373f07cc4d0ad773e6075fcae Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 9 Jan 2026 00:51:13 +0100 Subject: [PATCH] Handle potential race condition in request timeout --- RNS/Link.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index 698ce52..d6c3a44 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -1428,20 +1428,21 @@ class RequestReceipt(): now = time.time() if now > self.__resource_response_timeout: self.request_timed_out(None) + break time.sleep(0.1) def request_timed_out(self, packet_receipt): - self.status = RequestReceipt.FAILED - self.concluded_at = time.time() - self.link.pending_requests.remove(self) + if self in self.link.pending_requests and self.status == RequestReceipt.DELIVERED: + self.status = RequestReceipt.FAILED + self.concluded_at = time.time() + self.link.pending_requests.remove(self) - if self.callbacks.failed != None: - try: - self.callbacks.failed(self) - except Exception as e: - RNS.log("Error while executing request timed out callback from "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR) + if self.callbacks.failed != None: + try: self.callbacks.failed(self) + except Exception as e: + RNS.log("Error while executing request timed out callback from "+str(self)+". The contained exception was: "+str(e), RNS.LOG_ERROR) def response_resource_progress(self, resource):