-
-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Can't get server response while uploading with ChunkedInput #6706
Comments
@normanmaurer Gentle ping. Do you have any idea how I could achieve expected behavior? |
Actually, from RFC7230:
How can this be implemented with Netty? Any advice would be greatly appreciated. |
@slandelle what exactly you want to implement here ? Like stopping to write ? |
I would like to be able to read the early HTTP response the server sends before the FIN. Here's another example with some Wireshark dumps: https://groups.google.com/forum/#!topic/asynchttpclient/hGbinqPLHi0 |
Motivation: Netty doesn't provide any ability to handle early server response when uploading chunked file and instead, `IOException: Pipe closed` is thrown (see netty/netty#6706 for details). Changes: NettyInputStreamBody swallows ChannelOutputShutdownException in case it is thrown from netty's ChunkedWriteHandler. Result: Multipart early response is available to be handled properly.
Motivation: Netty doesn't provide any ability to handle early server response when uploading chunked file and instead, `IOException: Pipe closed` is thrown (see netty/netty#6706 for details). Changes: NettyInputStreamBody swallows ChannelOutputShutdownException in case it is thrown from netty's ChunkedWriteHandler. Result: Multipart early response is available to be handled properly.
Motivation: Netty doesn't provide any ability to handle early server response when uploading chunked file and instead, `IOException: Pipe closed` is thrown (see netty/netty#6706 for details). Changes: NettyInputStreamBody and BodyChunkedInput swallow ChannelOutputShutdownException in case it is thrown from netty's ChunkedWriteHandler. Result: Multipart early response is available to be handled properly.
This issue is kinda old... but I hit the same problem pretty recently. @slandelle thanks for the tests, they were really helpful. Talking about this code...
That's because In all other cases, to "fix" the problem we need to set
Step 3-5 happens concurrently with 2 (with unpredictable timings). If we hit the write failure during Step 2 because on the other side we've already committed Step 5... our channel automatically closes (due to the default value of So, in fact, it's resolvable but the behavior of the handler doesn't follow the RFC mentioned (we're not monitoring the network connection). @normanmaurer, would you suggest how this loop should be implemented correctly: "write, flush, check if there's something to read, read if necessary, goto begin or break if no need to write more"? It seems like resubmitting |
Expected behavior
When a request is invalid (eg missing auth header), a server will immediately send a response without waiting for the full request body, all the more during a large upload. It will then usually close the socket.
In this case, a Netty client should be able to read this response so it can react based on the information in there (eg www-authenticate header).
Actual behavior
Usually, when using a
ChunkedInput
, Netty client never reads the response, but crashes when trying to write on the socket because it was closed by the server.It seems
DefaultFileRegion
handles this better (I wasn't able to reproduce the issue with it so far).I get the expected response with Postman too.
Minimal yet complete reproducer code (or URL to code)
See https://github.com/slandelle/read-while-streaming-issue.
UploadTest
contains tests forDefaultFileRegion
,ChunkedFile
andChunkedNioFile
.Server side is Jetty based.
JettyServer
has a main method so you can run it standalone and test with Postman and such too.Netty version
4.1.22
JVM version (e.g.
java -version
)java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
OS version (e.g.
uname -a
)OSX 10.11.6 (El Capitan)
Darwin Kernel Version 15.6.0
The text was updated successfully, but these errors were encountered: