You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HttpClient is used to send content from a large file. File content is loaded with java.nio.channels.AsynchronousFileChannel which fills one chunk of 4096 bytes at a time and invokes a callback to provide it. The chunk is then pushed into a FluxSink. Then we call read again and wait for the next callback, and so on until all chunks are processed. As a result chunks can be pushed in rapid succession from multiple threads but not concurrently since the next read doesn't start until onNext returns.
The server is the MockWebServer from OkHttp so it simply records the received content. The received content matches the file content by size but the content is out of order.
Also note that if the input Flux is cached and subscribed to before it is sent, it works fine. That proves the content is provided correctly.
I was unable to confirm the fix. There is still some lingering issue.
I tried to remove @Ignore from our own test which is identical to the one above but using WebClient. The test fails with a stack trace like the one below, which, when you look at source around line 624, seems to indicate that it fails to parse the chunked input at a place where it is expecting an empty line:
SEVERE: MockWebServer[53439] connection from /127.0.0.1 crashed
java.lang.IllegalStateException: Expected empty but was: 1000
at okhttp3.mockwebserver.MockWebServer.readEmptyLine(MockWebServer.java:773)
at okhttp3.mockwebserver.MockWebServer.readRequest(MockWebServer.java:624)
at okhttp3.mockwebserver.MockWebServer.access$1400(MockWebServer.java:99)
Then I tried to understand why the sample I attached here does not fail. I even copied the same, identical test source over to our own tests and still the same result -- it fails when run in the Spring Framework sources but not in the attached project.
After comparing and ensuring dependency versions are the same, I decided it must be a timing issue which for some reason is more likely to show in our sources. So I lowered the chunk size from 4096 to 1024 to ensure a larger number of chunks are being sent, to provide more chances to demonstrate the issue. After that change the above repo began to fail more frequently, basically it fails pretty much revery time. I've updated the above repository accordingly.
Activity
[-]HttpClient corrupts upload content[/-][+]HttpClient corrupts uploaded content[/+]rstoyanchev commentedon Dec 22, 2017
I was unable to confirm the fix. There is still some lingering issue.
I tried to remove
@Ignorefrom our own test which is identical to the one above but usingWebClient. The test fails with a stack trace like the one below, which, when you look at source around line 624, seems to indicate that it fails to parse the chunked input at a place where it is expecting an empty line:Then I tried to understand why the sample I attached here does not fail. I even copied the same, identical test source over to our own tests and still the same result -- it fails when run in the Spring Framework sources but not in the attached project.
After comparing and ensuring dependency versions are the same, I decided it must be a timing issue which for some reason is more likely to show in our sources. So I lowered the chunk size from 4096 to 1024 to ensure a larger number of chunks are being sent, to provide more chances to demonstrate the issue. After that change the above repo began to fail more frequently, basically it fails pretty much revery time. I've updated the above repository accordingly.
rstoyanchev commentedon Jan 10, 2018
I confirmed the fix, thanks!