-
Notifications
You must be signed in to change notification settings - Fork 125
Fix crash when receiving 2xx response before stream is complete. #591
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
Fix crash when receiving 2xx response before stream is complete. #591
Conversation
Motivation It's totally acceptable for a HTTP server to respond before a request upload has completed. If the response is an error, we should abort the upload (and we do), but if the response is a 2xx we should probably just finish the upload. In this case it turns out we'll actually hit a crash when we attempt to deliver an empty body message. This is no good! Once that bug was fixed it revealed another: while we'd attempted to account for this case, we hadn't tested it, and so it turns out that shutdown would hang. As a result, I've also cleaned that up. Modifications - Tolerate empty circular buffers of bytes when streaming an upload. - Notify the connection that the task is complete when we're done. Result Fewer crashes and hangs.
eb0d918
to
6752103
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great patch and great fixes. One ask for a small comment.
@@ -267,6 +267,7 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler { | |||
writePromise.futureResult.whenComplete { result in | |||
switch result { | |||
case .success: | |||
self.connection.taskCompleted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a comment here? Something like:
If our final action is sendRequestEnd
this means, that we have already received the complete response. For this reason we must mark the connection as idle to the pool, once we have uploaded all body parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Lukasa, nice patch, just one super tiny nit.
@@ -1253,6 +1253,37 @@ class HTTPEchoHandler: ChannelInboundHandler { | |||
} | |||
} | |||
|
|||
class HTTP200DelayedHandler: ChannelInboundHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super tiny nit
class HTTP200DelayedHandler: ChannelInboundHandler { | |
final class HTTP200DelayedHandler: ChannelInboundHandler { |
Motivation
It's totally acceptable for a HTTP server to respond before a request
upload has completed. If the response is an error, we should abort the
upload (and we do), but if the response is a 2xx we should probably just
finish the upload.
In this case it turns out we'll actually hit a crash when we attempt to
deliver an empty body message. This is no good!
Once that bug was fixed it revealed another: while we'd attempted to
account for this case, we hadn't tested it, and so it turns out that
shutdown would hang. As a result, I've also cleaned that up.
Modifications
Result
Fewer crashes and hangs.
Resolves #562