-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[browser][websocket] Throw OperationCanceledException on connect #44722
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue Details
|
I understand that this change avoids doing extra work in case cancellation was already requested, but can you elaborate on how it fixes the test? What was happening before this change? |
Updated the PR comments to include the error message. |
But doesn't that suggest there's still a problem here? What happens if cancellation is requested while the connect is in flight? That should still produce an OperationCanceledException, but the error you pasted suggests it isn't. |
The test change is a little racey, so it should probably be reverted until we can test each stage but it was needed to get around the first change. |
I am not finding it racey. I will take a closer look but it seems to be working fine on my local machine. |
Will need to setup a websocket server locally to test some of the other stages. |
I meant in theory it might be able to fail on the host lookup before the cancellation, upon reflection that is unlikely, I'm fine either way. |
I have made multiple tests with these modifications against a local server as well as against a public websocket test echo server with no problems. The new test also works as expected. The original tests tests against a server that was not found but testing against a live server where the connection actually exists and succeeds also works. using (var clientSocket = new ClientWebSocket())
{
var cts = new CancellationTokenSource();
//Task t = clientSocket.ConnectAsync(new Uri("ws://" + Guid.NewGuid().ToString("N")), cts.Token);
Task t = clientSocket.ConnectAsync(new Uri("wss://echo.websocket.org"), cts.Token);
cts.Cancel();
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact checks need work.
src/libraries/System.Net.WebSockets.Client/tests/WebSocketHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs
Outdated
Show resolved
Hide resolved
…ancel was requested before.
- Add new supported property for skipping particular tests when Browser is detected and DOM is detected.
@kjpou1 I've pushed a rough pass at what I was suggesting because I realized we've discussed the complications before and I might have given contradictory information then. |
And now I'm realizing the platform check was probably written that way because of the old options throwing. If browser is the only unsupported case we can simplify it a lot more. |
Agree with the changes above. The reason we did not throw if WebSocket was not found was so that we could do rudimentary tests with the javascript engines. You are right that now that we have the tests stood up via browser we can now do it this way. The testing platform checks become a lot simpler. |
@lewing ping. Can you review this again? |
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/tests/WebSocketHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Browser.cs
Outdated
Show resolved
Hide resolved
Looks good to me but will wait on @lewing to approve |
if cancel was requested before.
This fixes the test
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs#L249
Fix #44720
Part of #44666
Test was failing with the following error:
See #45470 for more tests