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
{{ message }}
Repository navigation
Multipart File upload: Sometimes receiving empty files! [SPR-15955] #20507
On my example repo in branch "zero-bytes-files" i was able to reproduce a bug something to do with multipart file upload and the resulting transferTo method. I'm transferring files into temp files and i'm checking against zero byte files, so no data seems to be revceived on the netty server or its a bug in the synchronoss parser,
This test seems to be unfair, because it is starting 20 concurrent threads against the endpoint, but i was able to reproduce this bug on another setting, only with one thread and 100 iterations you are able to reproduce it. But you must host the first endpoint on a remote server. Some files will reproduce it more frequently, some files never. The concurrent threads force the test to reproduce it on localhost. You have to run the test min. five times, search for the first exception.
Tested with M3 (RC3) and SNAPSHOT(RC4) version from spring bootstrap, mainly on windows.
The receiver wasn't a Spring5 App and checks the request against zero byte files.
I can reproduce the error when the initial sender was Spring5 Webclient (Junit Test). I can't reproduce it when the sender was a Apache HTTP Client.
I've spent quite some time with your repro project given its complexity, I can't figure out what's the feature under test nor what is actually failing.
I can point you to a few places that could explain the current behavior though:
Mixing Thread management and reactive pipelines is bound to concurrency issues; the reactive pipeline itself is processing events on multiple threads. All bets are off at that point. I'd suggest you to use something like Flux.range and processing things on the Schedulers.elastic() to achieve concurrency if that's what you'd like.
I don't understand why you're calling a controller from another using the webclient; this is just adding indirection without exercising more parts of the framework
you're calling blocking code from within your reactive pipeline (creating a temp file for example), without scheduling those parts on a relevant scheduler
the FilePart.transferTo(file); call returns a Mono<Void>, which means you have to subscribe to it and wait for it to be completed before considering that bytes have been transferred. In my opinion, this is most likely the source of the problem here, since you might read the file before it's been written.
i reworked my example to make the test more simple. That was possible, cause i identified the problem is the WebClient sender, not the Server instance itself (see my last comment).
Some comments on your points.
I used concurrent Threads to force the problem on localhost. On the remote test i don't use multiple threads. So this isn't the problem here.
I tried to reproduce this bug on a simpler setting. I noticed this bug when i was using this setting: Client -> Server A -> Server B. I tried to simulate Server B with a second endpoint. I didn't know that the problem was the initial sender.
I don't know to how to schedule that. The transferTo Method is blokking anyway.
I can't reproduce the issue.
Note that by default there will be concurrency (up to 256 requested elements concurrently), so there are many requests in-flight at any moment.
I added the concurrency threads to reproduce it on localhost. Just removing concurrency against localhost to fix the issue doesn't help, when testing against remote server (network!) still fails without concurrency.
Because when i run this remote test with a simple HTTP Apache Client instead of the WebClient Junit Test i can't reproduce the zero byte file error.
I can create a third test with a apache http client if you want.
I've just confirmed that there might be an issue in MultipartHttpMessageWriter and/or ResourceHttpMessageWriter. In some cases, the file part looks like this:
There's been quite a few changes around the client and the multipart parser lately.
I can't reproduce this behavior anymore; I've set up a service instance running right now and the following test is consistently green on the latest snapshots:
Activity
spring-projects-issues commentedon Sep 12, 2017
Alexander Wilhelmer commented
Added a single threaded remote test. The server instance is hosted on ubuntu with SNAPSHOT version, so this bug don't hit windows only.
The server instance is online for max 7 days.
spring-projects-issues commentedon Sep 13, 2017
Alexander Wilhelmer commented
Okay i was able to reproduce with another setting, so i can say the problem is the WebClient Sender. Somehting to do with the Multipart POST.
I did this change on the Spring5 App:
The receiver wasn't a Spring5 App and checks the request against zero byte files.
I can reproduce the error when the initial sender was Spring5 Webclient (Junit Test). I can't reproduce it when the sender was a Apache HTTP Client.
spring-projects-issues commentedon Sep 20, 2017
Brian Clozel commented
Hi Alexander Wilhelmer
I've spent quite some time with your repro project given its complexity, I can't figure out what's the feature under test nor what is actually failing.
I can point you to a few places that could explain the current behavior though:
Threadmanagement and reactive pipelines is bound to concurrency issues; the reactive pipeline itself is processing events on multiple threads. All bets are off at that point. I'd suggest you to use something likeFlux.rangeand processing things on theSchedulers.elastic()to achieve concurrency if that's what you'd like.FilePart.transferTo(file);call returns aMono<Void>, which means you have to subscribe to it and wait for it to be completed before considering that bytes have been transferred. In my opinion, this is most likely the source of the problem here, since you might read the file before it's been written.Could you rework your sample with this feedback?
spring-projects-issues commentedon Sep 20, 2017
Alexander Wilhelmer commented
Hi Brian Clozel,
i reworked my example to make the test more simple. That was possible, cause i identified the problem is the WebClient sender, not the Server instance itself (see my last comment).
Some comments on your points.
Please update my repo and you have a very simple construct to reproduce.
spring-projects-issues commentedon Sep 20, 2017
Brian Clozel commented
I took your sample app and rewrote the test to avoid playing with threads:
I can't reproduce the issue.
Note that by default there will be concurrency (up to 256 requested elements concurrently), so there are many requests in-flight at any moment.
spring-projects-issues commentedon Sep 20, 2017
Alexander Wilhelmer commented
I added the concurrency threads to reproduce it on localhost. Just removing concurrency against localhost to fix the issue doesn't help, when testing against remote server (network!) still fails without concurrency.
spring-projects-issues commentedon Sep 20, 2017
Alexander Wilhelmer commented
Test RemoteTest.java:
Result:
spring-projects-issues commentedon Sep 20, 2017
Brian Clozel commented
This is getting really confusing - weren't you pointing to the
WebClientas being the culprit? What makes you think that?spring-projects-issues commentedon Sep 20, 2017
Alexander Wilhelmer commented
Because when i run this remote test with a simple HTTP Apache Client instead of the WebClient Junit Test i can't reproduce the zero byte file error.
I can create a third test with a apache http client if you want.
spring-projects-issues commentedon Sep 20, 2017
Brian Clozel commented
I've just confirmed that there might be an issue in
MultipartHttpMessageWriterand/orResourceHttpMessageWriter. In some cases, the file part looks like this:Headers ans boundary are properly written, but not the actual file content.
spring-projects-issues commentedon Sep 25, 2017
Brian Clozel commented
There's been quite a few changes around the client and the multipart parser lately.
I can't reproduce this behavior anymore; I've set up a service instance running right now and the following test is consistently green on the latest snapshots:
Alexander Wilhelmer, could you let me know if you can still reproduce that issue against that service instance?