Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Disable SocketsHttpHandler's concurrent content sends - #27341

Merged
stephentoub merged 2 commits into
dotnet:masterfrom
stephentoub:removeconcurrentsend
Feb 22, 2018
Merged

stephentoub merged 2 commits into
dotnet:masterfrom
stephentoub:removeconcurrentsend

Conversation

@stephentoub

Copy link
Copy Markdown
Member

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

@davidsh

davidsh commented Feb 21, 2018

Copy link
Copy Markdown
Contributor

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is _currentRequest actually used anymore, aside from asserts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@geoffkizer

Copy link
Copy Markdown

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.

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.

@geoffkizer

Copy link
Copy Markdown

LGTM, minor issues above

@geoffkizer

Copy link
Copy Markdown

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.
@stephentoub

Copy link
Copy Markdown
Member Author

@dotnet-bot test Outerloop Windows x64 Debug Build please
@dotnet-bot test Outerloop Linux x64 Release Build please

@stephentoub

Copy link
Copy Markdown
Member Author

@stephentoub
stephentoub merged commit fecb772 into dotnet:master Feb 22, 2018
@stephentoub
stephentoub deleted the removeconcurrentsend branch February 22, 2018 19:58
@karelz karelz added this to the 2.1.0 milestone Mar 10, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants