Skip to content

Inconsistent behavior of ClientWebSockets on cancellation #29763

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

Closed
matthid opened this issue Jun 4, 2019 · 5 comments · Fixed by dotnet/corefx#38204
Closed

Inconsistent behavior of ClientWebSockets on cancellation #29763

matthid opened this issue Jun 4, 2019 · 5 comments · Fixed by dotnet/corefx#38204
Assignees
Labels
area-System.Net bug tenet-compatibility Incompatibility with previous versions or .NET Framework tenet-reliability Reliability/stability related issue (stress, load problems, etc.)
Milestone

Comments

@matthid
Copy link

matthid commented Jun 4, 2019

In addition to the documentation issue (see @JohBa comment) I'd like to report this as API-bug as well as all current implementations seems to behave differently.

Interesting is the response from @karelz :

Failed connection will throw exception. If the source was cancallation, then it will be TaskCancelledException, otherwise different exception.
Does it help?

Because no implementation actually has this (imho expected) behavior.

For completeness:

class Program
{
    static async Task Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        var websocket = new ClientWebSocket();
        try
        {
           await websocket.ConnectAsync(new Uri("wss://localhost:443/ws"), new CancellationTokenSource(TimeSpan.FromMilliseconds(10)).Token);
        }
        catch (WebSocketException e)
        {
            Console.WriteLine(e);
        }
        Console.ReadLine();
    }
}
  • netcore2.2
    System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server 
    ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
    
  • net461
    System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
    ---> System.Net.WebException: The request was aborted: The request was canceled.
    

Interestingly, there not even a nice way to "detect" the request was canceled in the full framework (besides checking the token in the catch block, which only works directly on the call-site).

@matthid
Copy link
Author

matthid commented Jun 4, 2019

@stephentoub stephentoub self-assigned this Jun 4, 2019
@marklio
Copy link

marklio commented Jun 6, 2019

Marking reliability as we've seen unexpected cancellation behaviors lead to reliability issues.

@stephentoub
Copy link
Member

Marking reliability as we've seen unexpected cancellation behaviors lead to reliability issues.

This is different than the ones you've seen though, Mark, no? This case is promptly responding to a cancellation request, and an OperationCanceledException is being thrown, it's just a question of whether that exception is wrapped in something else or not.

That said, I don't really care what labels are used. If there's value to you in it being tagged as reliability, ok :)

@marklio
Copy link

marklio commented Jun 6, 2019

This is different than the ones you've seen though, Mark, no?

I definitely agree. I wanted to mark this because it is "related" to the class of issues we've seen. Like exception handling in general, we see that code dealing with cancellation has poor test coverage across the ecosystem, and because it is "stress-like" in its difficultly to achieve meaningfully good coveragein unit tests (you need to cancel at every possible code location with a unique behavior), something like this could easily cause a lurking reliability issue in customer code.

This one is tricky as it is entangled with compat, so I wouldn't make a call on what to do based on reliability alone.

@stephentoub
Copy link
Member

Ok :)

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net bug tenet-compatibility Incompatibility with previous versions or .NET Framework tenet-reliability Reliability/stability related issue (stress, load problems, etc.)
Projects
None yet
4 participants