Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add two missing ConfigureAwait(false) calls in SocketsHttpHandler #29465

Merged
merged 2 commits into from
May 3, 2018

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented May 2, 2018

ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false). If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete. The fix is simply to add .ConfigureAwait(false).

As long as I was fixing that, I also reviewed all awaits in SocketsHttpHandler and found one more that was missing .ConfigureAwait(false), in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.

And added some tests.

Fixes https://github.com/dotnet/corefx/issues/29453
cc: @geoffkizer, @davidsh, @ayende, @pjanotti

ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false).  If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete.  The fix is simply to add `.ConfigureAwait(false)`.

As long as I was fixing that, I also reviewed all `await`s in SocketsHttpHandler and found one more that was missing `.ConfigureAwait(false)`, in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.

And added some tests.
string response;
switch (chunked)
{
case false:

Choose a reason for hiding this comment

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

Nit: there's an enum ContentMode for this in HttpClientHandler_ResponseDrain_Test, perhaps we should make that a first class thing (i.e., move the enum to LoopbackServer and add overloads that take it)

Or if not for this checkin, perhaps we could file an issue to do this in the future...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@stephentoub
Copy link
Member Author

Thanks for the reviews, @davidsh and @geoffkizer.

@stephentoub stephentoub merged commit 9e8c200 into dotnet:master May 3, 2018
@stephentoub stephentoub deleted the fixsyncctx branch May 3, 2018 02:25
stephentoub added a commit to stephentoub/corefx that referenced this pull request May 3, 2018
…tnet#29465)

ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false).  If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete.  The fix is simply to add `.ConfigureAwait(false)`.

As long as I was fixing that, I also reviewed all `await`s in SocketsHttpHandler and found one more that was missing `.ConfigureAwait(false)`, in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.
stephentoub added a commit that referenced this pull request May 3, 2018
…9465) (#29470)

ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false).  If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete.  The fix is simply to add `.ConfigureAwait(false)`.

As long as I was fixing that, I also reviewed all `await`s in SocketsHttpHandler and found one more that was missing `.ConfigureAwait(false)`, in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.
@karelz karelz added this to the 2.2.0 milestone May 5, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…tnet/corefx#29465)

* Add two missing ConfigureAwait(false) calls in SocketsHttpHandler

ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false).  If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete.  The fix is simply to add `.ConfigureAwait(false)`.

As long as I was fixing that, I also reviewed all `await`s in SocketsHttpHandler and found one more that was missing `.ConfigureAwait(false)`, in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.

And added some tests.

* Refactor ContentMode support in tests


Commit migrated from dotnet/corefx@9e8c200
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.

Hangs with HttpClientHandler and AutomaticDecompression in 2.1 preview
4 participants