question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR Core Abort() leads to undefined state

See original GitHub issue

Describe the bug

Calling Abort() in a hub leads to the client’s connection status being set to Reconnecting, but only sometimes is a reconnection attempt made. Client’s Closed callback is not invoked when this happens. Stopping the connection on the client, while in this state, throws an exception (this part is correct I guess).

Expected behaviour: When Abort() is called in a hub on server: Client’s Closed callback should get invoked, and client’s status should be set to Disconnected. Client should not try to reconnect. It is problematic that it ends up in a Reconnecting state and sometimes tries to reconnect, while completely skipping the closed callback.

To Reproduce

In server’s hub, call the following. (Please note that I am actually calling Abort() from outside the hub, by storing the context of the hub in a ConcurrentDictionary in a singleton service as per https://github.com/dotnet/aspnetcore/issues/5333, until there is a real way to disconnect clients outside the hub. I would assume the bug is exposed even when just calling Abort() inside a hub such as:).

this.Context.Abort();

On client:

        public async Task Connect()
        {
            // close existing connection to allow for a new token
            if (this.connection != null)
            {
                if (this.connection.State != HubConnectionState.Disconnected)
                    await this.connection.StopAsync();
                await this.connection.DisposeAsync(); // TODO: is this needed??
                this.connection = null;
            }

            this.connection = new HubConnectionBuilder()
                .WithUrl("someUrl", (options) =>
                    .options.AccessTokenProvider = () => Task.FromResult("SomeToken");
                )
                .WithAutomaticReconnect()
                .Build();

            this.connection.Closed -= this.OnConnectionClosed;
            this.connection.Closed += this.OnConnectionClosed;
            await this.connection.StartAsync();
        }

        private Task OnConnectionClosed(Exception exception)
        {
            Console.WriteLine($"Connection closed: {exception}");
            if (exception is HubException)
            {
                // cleanup here
            }
            return Task.CompletedTask;
        }

Further technical details

  • ASP.NET Core version: 3.1.2

  • Include the output of dotnet --info: .NET Core SDK (reflecting any global.json): Version: 3.1.200 Commit: c5123d973b

Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.200/

Host (useful for support): Version: 3.1.2 Commit: 916b5cba26

.NET Core SDKs installed: 3.1.200 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version: VS For Mac 8.6 Preview (build 4387)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Sep 11, 2020
1reaction
halter73commented, Sep 2, 2020

We still need to make the fix, but that’s the plan.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR Core detect if connection is closed by client or server
Error: "WebSocket closed with status code: 1006 ()." So my problem could be easily solved by checking if the error is undefined:
Read more >
SignalR Troubleshooting
Take a look at ASP.NET Core SignalR. This document describes common troubleshooting issues with SignalR.
Read more >
How to Implement SignalR Automatic Reconnect with ...
In this article, we are going to look at the SignalR Automatic Reconnect feature and how to implement automatic reconnect in our SignalR...
Read more >
Using ASP.NET Core SignalR with Vue.js (to create a mini ...
This article introduces the main concepts and building blocks of SignalR by implementing a minimalistic version of StackOverflow.com using an ...
Read more >
Getting started with SignalR using ASP.NET Core and Angular
This article shows how to setup a first SignalR Hub in ASP.NET Core 2.2 and use it with an Angular client. SignalR was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found