fix file chunking corruption (#7338)

This commit is contained in:
diwu-sf 2025-03-20 12:21:36 -07:00 committed by GitHub
parent b0030d3a2b
commit 3856a896ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,4 @@
import os
import shutil
import tempfile
import threading
from abc import abstractmethod
@ -149,7 +148,10 @@ class ActionExecutionClient(Runtime):
with tempfile.NamedTemporaryFile(
suffix='.zip', delete=False
) as temp_file:
shutil.copyfileobj(response.raw, temp_file, length=16 * 1024)
for chunk in response.iter_content(chunk_size=16 * 1024):
if chunk: # filter out keep-alive new chunks
temp_file.write(chunk)
temp_file.flush()
return Path(temp_file.name)
except requests.Timeout:
raise TimeoutError('Copy operation timed out')