Skip to content
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

Allow SocketsHttpHandler.ConnectCallback for sync requests #45300

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

stephentoub
Copy link
Member

HTTP/1.1 support with sync requests currently doesn't work when a ConnectCallback is specified, even though a developer who wanted to make synchronous requests could provide a synchronously-completing callback.

This also consolidates the connect logic across sync/async, avoids an extra delegate, etc.

Contributes to #44876
cc: @geoffkizer, @scalablecory, @ManickaP

HTTP/1.1 support with sync requests currently doesn't work when a ConnectCallback is specified, even though a developer who wanted to make synchronous requests could provide a synchronously-completing callback.

This also consolidates the connect logic across sync/async, avoids an extra delegate, etc.
@ghost
Copy link

ghost commented Nov 28, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

HTTP/1.1 support with sync requests currently doesn't work when a ConnectCallback is specified, even though a developer who wanted to make synchronous requests could provide a synchronously-completing callback.

This also consolidates the connect logic across sync/async, avoids an extra delegate, etc.

Contributes to #44876
cc: @geoffkizer, @scalablecory, @ManickaP

Author: stephentoub
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

// we could add a Boolean to SocketsHttpConnectionContext (https://github.com/dotnet/runtime/issues/44876) to let the callback know whether
// this request is sync or async. For now, log it and block.
Trace($"{nameof(SocketsHttpHandler.ConnectCallback)} completing asynchronously for a synchronous request.");
stream = streamTask.AsTask().GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we rather throw instead of blocking for sync?

Copy link
Member Author

@stephentoub stephentoub Nov 30, 2020

Choose a reason for hiding this comment

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

That was what I did initially, but I think that's problematic because it's non-deterministic: if the operation happens to complete by the time we check, it won't throw, but if it doesn't, it will. That then makes it much more likely you'll only experience the failures once you deploy. We already block in other circumstances as well, e.g. if you have a MaxConnectionsPerServer set, we'll block waiting for an available connection for sync operations, rather than throwing, so not throwing here is consistent with that, too. This is different from the base Send/SendAsync methods, where in general not overriding a relevant sync method in the handler chain will deterministically fail; on top of that, all of our implementations shipped "in the box" override appropriately.

Copy link
Member

Choose a reason for hiding this comment

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

I guess my original concern will get addressed with the proper implementation of #44876, and you're reasoning makes sense here. So thanks.

@stephentoub stephentoub merged commit 296f4de into dotnet:master Nov 30, 2020
@stephentoub stephentoub deleted the syncconnectcallback branch November 30, 2020 18:52
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants