Repository navigation
Disable SocketsHttpHandler's concurrent content sends - #27341
Conversation
This has been an ask of some folks where they wanted the HTTP stack to process the response in order to cancel sending (or avoid altogether sending) a request body. I'll have to look the issue in GitHub where there was a discussion about this. WinHttpHandler could not do this because of the sequential nature of the underlying WinHTTP APIs which don't really support that. |
| return _connection.FlushAsync(); | ||
| } | ||
|
|
||
| if (_connection._currentRequest == null) |
There was a problem hiding this comment.
There is a comment below in WriteChunkAsync about duplex communication. At the very least, the comment should be removed. Possibly the logic there should change too, though that may be beyond the scope of this PR.
There was a problem hiding this comment.
I removed the comment and the explicit flushing. We do a flush at the end of copying the content; that should be sufficient, and of course any flushes that happen along the way as the buffer fills. I've also changed ContentLengthWriteStream to use HttpConnection.WriteAsync instead of HttpConection.WriteWithoutBufferingAsync, and opened an issue for the CONSIDER comment in WriteWithoutBufferingAsync (WriteAsync will also skip the buffer if the writes are sufficiently large).
|
|
||
| public override Task WriteAsync(ReadOnlyMemory<byte> source, CancellationToken ignored) | ||
| { | ||
| Debug.Assert(_connection._currentRequest != null); |
There was a problem hiding this comment.
Is _currentRequest actually used anymore, aside from asserts?
There was a problem hiding this comment.
Just asserts and logging now. Although we could potentially use it in places to avoid passing the instance around and storing it in various async state machines.
Thanks, would be great to understand this better. I can definitely imagine wanting to cancel sending the body. That said, isn't that what 100-continue is for? Maybe that's not sufficient in all cases. If we want to support cancelling the send when an early response is received, that seems easier to do that full duplex communication. |
|
LGTM, minor issues above |
|
Related to my WriteChunkAsync above: Since we aren't supporting duplex communication, we may want to revisit how buffering and flushing works in the content streams. This may be beyond the scope of this PR but we should at least track it. |
SocketsHttpHandler currently has some support for allowing request content sending to run concurrently with response content receiving. However, we don't actually have a need for this, and there are a lot of subtleties that would need to be made robust, e.g. how to handle exceptions that occur concurrently in the sending and receiving. For now, we're removing it. Unless ExpectContinue is set to true, we just send the content before receiving the response, and if it is set, we start the send and then wait for it once we've received the final status code from the server.
90e14eb to
0b9b03b
Compare
0b9b03b to
39ad031
Compare
|
@dotnet-bot test Outerloop Windows x64 Debug Build please |
|
@dotnet-bot test OSX x64 Debug Build please (https://github.com/dotnet/corefx/issues/27375) |
…27341) * Disable SocketsHttpHandler's concurrent content sends SocketsHttpHandler currently has some support for allowing request content sending to run concurrently with response content receiving. However, we don't actually have a need for this, and there are a lot of subtleties that would need to be made robust, e.g. how to handle exceptions that occur concurrently in the sending and receiving. For now, we're removing it. Unless ExpectContinue is set to true, we just send the content before receiving the response, and if it is set, we start the send and then wait for it once we've received the final status code from the server. * Address PR feedback Commit migrated from dotnet/corefx@fecb772
SocketsHttpHandler currently has some support for allowing request content sending to run concurrently with response content receiving. However, we don't actually have a need for this, and there are a lot of subtleties that would need to be made robust, e.g. how to handle exceptions that occur concurrently in the sending and receiving. For now, we're removing it. Unless ExpectContinue is set to true, we just send the content before receiving the response, and if it is set, we start the send and then wait for it once we've received the final status code from the server.
cc: @geoffkizer, @davidsh, @wfurt
Fixes #https://github.com/dotnet/corefx/issues/27324