Skip to content

Delegating File downloads sends incomplete chunks [SPR-15949] #22194

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

Closed
spring-projects-issues opened this issue Sep 10, 2017 · 14 comments
Closed
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 10, 2017

Alexander Wilhelmer opened SPR-15949 and commented

I noticed problems when u using this construct:

public Flux<DataBuffer> getFileContent(String url) {
     Mono<ClientResponse> exchange = webClientService.getWebClient().get().uri(url).accept(MediaType.APPLICATION_OCTET_STREAM).exchange();
     return exchange.flatMapMany(clientResponse -> {
        return clientResponse.bodyToFlux(DataBuffer.class);
     });
   }

You have to use a HTTP source with transcoding: chunked header without a content-length header. The problem of incomplete chunks only appears when you deploy the spring application on a windows system. I can't reproduce it on linux e.g. ubuntu. I'm using Windows Server 2008 R2 and Windows Server 2003, both with java 1.8 update 144. Requests against localhost works too, you have to stream over network!

Example: I deployed the app on windows. Just call http://217.79.182.40:8091/download/stream/102400 a few times. You will get a Network Error sometimes (1-3 errors on ten attempts). I'll keep that server online for max 7 days.

Source see at reference URL.


Affects: 5.0 RC3

Reference URL: https://github.com/awilhelmer/streambug

Attachments:

Issue Links:

Referenced from: commits ec2218c

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Hello Alexander Wilhelmer,

Thanks for all your efforts; thanks to your detailed description, we've managed to narrow things down to a (possibly fixed) bug in reactor-netty.

Could you try upgrading your application to Spring Boot 2.0.0.BUILD-SNAPSHOT and see if the issue is gone?

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

I tried with 2.0.0.BUILD-SNAPSHOT.
The Bug still exists:

!screenshot-1.png!

I found a file, which nearly always produce the error. But it contained personal data, so i can't make it public .... It has 221.182 Bytes and on disc 221.184 Bytes. Maybe it helps....

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

The test you're using doesn't look quite right to me. You're asking for a Mono when the server will give you a Flux<DataBuffer>, and the DataBufferDecoder doesn't support reducing to a Mono. If you'd like to deal with low-level DataBuffer instances, it's your job to manage those pooled resources.

Rewriting that test to reduce it to a Mono<DataBuffer>, things work properly with httpbin.org, but there's indeed an issue with your server instance. Is your server currently running the snapshot version?

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

The test isn't active and don't makes sense, cause requests against localhost are working fine.

The Server is running with RC3. I tested with SNAPSHOT on a local server from my employer. I can deploy the app with SNAPSHOT on the server in the evening today.

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

I updated the reference project to SNAPSHOT and added a remote test and corrected the local test.

This is the error on the RemoteTest:

java.lang.AssertionError: expected:<102400> but was:<98304>

> GET http://217.79.182.40:8091/download/stream/102400
> WebTestClient-Request-Id: [6]
> Accept: [application/octet-stream]

No content

< 200 OK
< Last-Modified: [Wed, 31 Dec 1969 23:59:59 GMT]
< Content-Type: [application/octet-stream]
< Transfer-Encoding: [chunked]
< Date: [Mon, 11 Sep 2017 15:56:03 GMT]

Unknown charset (98304 bytes)

So you can see that always the last chunk is missing, i saw the chunk size is 4096 bytes.

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

The remote server is already deployed with SNAPSHOT

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Yes, Violeta Georgieva managed to reproduce the issue on her gear. I couldn't reproduce it on win8 + in a local VM. You're right, the network probably comes into play.
I've streamlined things a bit in my fork: https://github.com/bclozel/streambug

We're still looking into this. This is not related to reactor-netty as a server, since this repro project is using Tomcat. So this might be the client, or a subtle combination of several things.

Thanks for your efforts!

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

I tested on a remote linux instance. No errors. Localhost no errors too.

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

i will test it with jetty and undertow too now. so the server might be offline for some moments.

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

With Jetty:
Caused by: java.lang.AssertionError: expected:<102400> but was:<100862>
at org.junit.Assert.fail(Assert.java:88)

With Undertow:
No errors!

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

BTW. Today i saw this error on a JSON only endpoint with a array with a lot of data (30 elements with ~20 attributes, very unusual!).It can be the same cause, so this problem can maybe more critical for windows hosts.

@spring-projects-issues
Copy link
Collaborator Author

Violeta Georgieva commented

Hi,

I can reproduce the issue only with Tomcat/Jetty as runtimes.
My analysis showed that sometimes the last flush operation is not performed as expected.

I prepared here a PR with a change that ensures the last flush.
#1526

Do you think you can rebuild on your side and test the change?

Regards,
Violeta

@spring-projects-issues
Copy link
Collaborator Author

Alexander Wilhelmer commented

Hi,

thanks for your great work. I updated my server and run this test five times. Can't reproduce now with your PR.

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

Thanks for the hard work Violeta Georgieva and Alexander Wilhelmer - this is now in master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant