From cb023cde402aa6d903be349e9bf16dd97d46f6d3 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 26 Feb 2022 18:27:11 +0100 Subject: [PATCH] Fixed potential race condition in resource assembly --- RNS/Link.py | 3 ++- RNS/Resource.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RNS/Link.py b/RNS/Link.py index 1978389..9386b84 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -551,7 +551,8 @@ class Link: break if remove != None: - self.pending_requests.remove(remove) + if remove in self.pending_requests: + self.pending_requests.remove(remove) def request_resource_concluded(self, resource): if resource.status == RNS.Resource.COMPLETE: diff --git a/RNS/Resource.py b/RNS/Resource.py index de4a89b..12f968e 100644 --- a/RNS/Resource.py +++ b/RNS/Resource.py @@ -143,6 +143,8 @@ class Resource: def __init__(self, data, link, advertise=True, auto_compress=True, callback=None, progress_callback=None, timeout = None, segment_index = 1, original_hash = None, request_id = None, is_response = False): data_size = None resource_data = None + self.assembly_lock = False + if hasattr(data, "read"): data_size = os.stat(data.name).st_size self.total_size = data_size @@ -601,7 +603,8 @@ class Resource: self.receiving_part = False - if self.received_count == self.total_parts: + if self.received_count == self.total_parts and not self.assembly_lock: + self.assembly_lock = True self.assemble() elif self.outstanding_parts == 0: # TODO: Figure out if there is a mathematically