Skip to content

Commit

Permalink
Fix OOM error after uploading large chunked file
Browse files Browse the repository at this point in the history
fixes: #2573
  • Loading branch information
gerrod3 authored and dralley committed Apr 27, 2022
1 parent 0888384 commit ba7ab5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/2573.bugfix
@@ -0,0 +1 @@
Fixed OOM error after uploading large chunked files.
7 changes: 4 additions & 3 deletions pulpcore/app/files.py
Expand Up @@ -34,15 +34,16 @@ def from_file(cls, file):
name = os.path.basename(file.name)
instance = cls(name, "", file.size, "", "")
instance.file = file
data = file.read()
# Default 1MB
while data := file.read(1048576):
for hasher in models.Artifact.DIGEST_FIELDS:
instance.hashers[hasher].update(data)

# calling the method read() moves the file's pointer to the end of the file object,
# thus, it is necessary to reset the file's pointer position back to 0 in case of
# calling the method read() again from another place
file.seek(0)

for hasher in models.Artifact.DIGEST_FIELDS:
instance.hashers[hasher].update(data)
return instance


Expand Down

0 comments on commit ba7ab5e

Please sign in to comment.