Use seeker when available on request body #50
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
I tried to upload a large file (~30GB) over night with on my Raspberry Pi using the CLI client. Therefore I opened up a Docker container with the binary and the file to upload inside and started the upload from there. I noticed that the upload always gets canceled after a few minutes with log output
Killed
.The problem occurs because the contents of the file are written into a buffer on upload, which filled up the RAM of the Pi (4GB) which eventually caused Linux to kill the process.
gowebdav/requests.go
Lines 12 to 16 in 73a7f0b
I was also able to reproduce this on my Windows system.
Solution
I changed the
req
function so that it checks if the passedbody
Reader implementsio.Seeker
. If this is the case, the streams cursor will be reset to start before request which eliminates the requirement of the retry buffer. Otherwise, if the Reader is not seekable, the stream will be teed into the retry buffer.Also, I've renamed the buffer
ab
toretryBuf
for better understanding.