mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
Fix crash when receiving 2xx response before stream is complete. (#591)
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. his 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.
This commit is contained in:
@@ -267,6 +267,10 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
|
||||
writePromise.futureResult.whenComplete { result in
|
||||
switch result {
|
||||
case .success:
|
||||
// If our final action was `sendRequestEnd`, that means we've already received
|
||||
// the complete response. As a result, once we've uploaded all the body parts
|
||||
// we need to tell the pool that the connection is idle.
|
||||
self.connection.taskCompleted()
|
||||
oldRequest.succeedRequest(buffer)
|
||||
case .failure(let error):
|
||||
oldRequest.fail(error)
|
||||
|
||||
Reference in New Issue
Block a user