Skip to content

HttpClient corrupts uploaded content #232

Closed

Description

@rstoyanchev

See test case in this repository https://github.com/rstoyanchev/spr16246.

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.

Originally reported in SPR-16246.

Activity

  1. changed the title [-]HttpClient corrupts upload content[/-] [+]HttpClient corrupts uploaded content[/+] on Dec 1, 2017
  2. added this to the 0.7.3.RELEASE milestone on Dec 4, 2017
  3. added
    type/bug
    on Dec 4, 2017
  4. rstoyanchev commented on Dec 22, 2017

    @rstoyanchev
    ContributorAuthor

    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.

  5. rstoyanchev commented on Jan 10, 2018

    @rstoyanchev
    ContributorAuthor

    I confirmed the fix, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions