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

Fix sync ConnectHelper.Connect #40880

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Conversation

ManickaP
Copy link
Member

@ManickaP ManickaP commented Aug 15, 2020

Redo of #39514

Fixes #40876
Fixed #40881

@ghost
Copy link

ghost commented Aug 15, 2020

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

@ManickaP ManickaP requested a review from a team August 15, 2020 09:13
@@ -62,6 +62,9 @@ public static Connection Connect(string host, int port, CancellationToken cancel
{
socket.Connect(new DnsEndPoint(host, port));
}

// Since we only do GracefulShutdown in SocketsHttpHandler code, Connection.FromStream() should match SocketConnection's behavior:
return Connection.FromStream(new NetworkStream(socket, ownsSocket: true), localEndPoint: socket.LocalEndPoint, remoteEndPoint: socket.RemoteEndPoint);
Copy link
Member Author

Choose a reason for hiding this comment

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

The key here is to have NetworkStream ctor inside the try block. If having Connection.FromStream inside it as well is not desired, this can be split into 2 lines.

@ManickaP ManickaP merged commit a32d979 into dotnet:master Aug 15, 2020
@ManickaP ManickaP deleted the mapichov/40876_fix branch August 15, 2020 12:30
@antonfirsov
Copy link
Member

antonfirsov commented Aug 15, 2020

@ManickaP thanks a lot for dealing with this. I think neither my nor @scalablecory 's PR respected this scenario. Wouldn't it make sense to add a regression test for it?

(I mean something less fragile than the HttpWebRequest test that used to fail occasionally.)

@ManickaP
Copy link
Member Author

I don't how would you design such test. The error manifested only if cancellation happened exactly between socket creation and NetworkStream constructor.

@geoffkizer
Copy link
Contributor

This is an improvement from what it did previously, but isn't it still going to result in ObjectDisposedException? That seems bad.

@ManickaP
Copy link
Member Author

If the dispose is a result of cancellation (which was the case here) then it won't since it gets mapped to TaskCanceledException in CreateWrappedException

@geoffkizer
Copy link
Contributor

That makes sense, thanks.

I still think it's a bit odd that the OperationCancelledException will end up with an inner error of ObjectDisposedException, but I guess that's what we do today anyway.

@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants