-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream request bodies when proxying to outpack server. #107
Conversation
If a client tries to upload a file to Packit using the outpack API, the Packit server would try to buffer the entire request in memory before sending it out to the outpack server. This wasn't obvious from the code but an implementation detail of the HTTP libraries being used. This caused issues when clients upload very large files - too large to fit in memory. The Packit server would run out of heap space and cause an exception. Thankfully the issue is simple to fix, and the HTTP library only needs to be configured with `setBufferRequestBody(false)`. In fact, [according to the docs][setBufferRequestBody], the latest version of Spring has these flags set by default. We don't, however, use this version of Spring yet. Steps to reproduce: 1. Create a 1GB `data` file: ``` dd if=/dev/random of=data bs=1M count=1024 ``` 2. Start the Packit server with a 128MB maximum heap size: ``` java -Xmx128m -jar app/build/libs/app.jar ``` 3. Calculate the hash of the file and upload it to the server: ``` hash=$(sha256sum data | awk '{ print $1 }') curl -X POST -T data \ -H "Authorization: Bearer $TOKEN" \ http://127.0.0.1:8080/outpack/file/sha256:$hash ``` Without this change, step 3 results in a `OutOfMemoryError` exception. [setBufferRequestBody]: https://docs.spring.io/spring-framework/docs/6.1.0/javadoc-api/org/springframework/http/client/SimpleClientHttpRequestFactory.html#setBufferRequestBody(boolean)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## mrc-5677-refactor-clients #107 +/- ##
==========================================================
Coverage 96.00% 96.00%
==========================================================
Files 106 106
Lines 975 975
Branches 252 252
==========================================================
Hits 936 936
Misses 38 38
Partials 1 1 ☔ View full report in Codecov by Sentry. |
I spent way too long trying to write integration tests for this but got no where. I had code that created a 1GB With I tried removing The docs for This is the point where I gave up. |
Re-opened as #108. I don't understand what GItHub did here and it won't let me re-open. |
If a client tries to upload a file to Packit using the outpack API, the Packit server would try to buffer the entire request in memory before sending it out to the outpack server. This wasn't obvious from the code but an implementation detail of the HTTP libraries being used.
This caused issues when clients upload very large files - too large to fit in memory. The Packit server would run out of heap space and cause an exception.
Thankfully the issue is simple to fix, and the HTTP library only needs to be configured with
setBufferRequestBody(false)
. In fact, according to the docs, the latest version of Spring has these flags set by default. We don't, however, use this version of Spring yet.Steps to reproduce:
Create a 1GB
data
file:Start the Packit server with a 128MB maximum heap size:
Calculate the hash of the file and upload it to the server:
Without this change, step 3 results in a
OutOfMemoryError
exception.