Fixed potential race condition in resource assembly

This commit is contained in:
Mark Qvist 2022-02-26 18:27:11 +01:00
parent 17be289f37
commit cb023cde40
2 changed files with 6 additions and 2 deletions

View File

@ -551,6 +551,7 @@ class Link:
break break
if remove != None: if remove != None:
if remove in self.pending_requests:
self.pending_requests.remove(remove) self.pending_requests.remove(remove)
def request_resource_concluded(self, resource): def request_resource_concluded(self, resource):

View File

@ -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): 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 data_size = None
resource_data = None resource_data = None
self.assembly_lock = False
if hasattr(data, "read"): if hasattr(data, "read"):
data_size = os.stat(data.name).st_size data_size = os.stat(data.name).st_size
self.total_size = data_size self.total_size = data_size
@ -601,7 +603,8 @@ class Resource:
self.receiving_part = False 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() self.assemble()
elif self.outstanding_parts == 0: elif self.outstanding_parts == 0:
# TODO: Figure out if there is a mathematically # TODO: Figure out if there is a mathematically