Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Expose a connection state from HubConnection #2127

Closed
davidfowl opened this issue Apr 21, 2018 · 15 comments
Closed

Expose a connection state from HubConnection #2127

davidfowl opened this issue Apr 21, 2018 · 15 comments
Assignees
Labels
3 - Done cost: S Will take up to 2 days to complete type: Enhancement
Milestone

Comments

@davidfowl
Copy link
Member

We should expose a ConnectionState enum from the HubConnection so that it's possible to avoid throwing from SendAsync if the HubConnection wasn't connected. Today it requires you storing your own bool and setting it in the Closed event.

@JamesNK
Copy link
Member

JamesNK commented May 14, 2018

Also need state on JS client.

@moozzyk
Copy link
Contributor

moozzyk commented May 15, 2018

Only that SendAsync can still throw if the connection/transport gets disconnected after the check and before actually sending data...

@davidfowl
Copy link
Member Author

Yep.

@MagicAndre1981
Copy link

when will this be released? Microsoft.AspNetCore.SignalR.Client Version 1.0.2 doesn't include this.

I assume the 2.2.0 means Asp.Net Core 2.2? Why not sync SignalR versions to match Asp.Net Core to easily see which version has the fix?

@davidfowl
Copy link
Member Author

when will this be released? Microsoft.AspNetCore.SignalR.Client Version 1.0.2 doesn't include this.

1.1, which will ship with ASP.NET Core 2.2

I assume the 2.2.0 means Asp.Net Core 2.2? Why not sync SignalR versions to match Asp.Net Core to easily see which version has the fix?

We'll sync it in 3.0

@MagicAndre1981
Copy link

I just read the ASP.NET Core 2.2 Roadmap and this means we have to wait until end of this year to get the fix, correct?

@davidfowl
Copy link
Member Author

That's correct. There are packages on the myget feed if you want to try them out right now but the final build will be with ASP.NET Core 2.2

@MagicAndre1981
Copy link

so I have to use this version?

@MagicAndre1981
Copy link

the version works and I see the State property. How reliable are the 1.1 previews? Will we see radical API changes or only for 3 builds?

btw, it would be better to have 2 feeds (1 feed for 3.0 and 1 for 2.2/1.1).

@MagicAndre1981
Copy link

I've tested the nightly versions a bit more, but it doesn't work the same like in the old SignalR. In my case 3 time the state is disconnected and I start 3 connections not only 1 like in old SignalR.

Application started. Press Ctrl+C to shut down.
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HLG2H0UTOJ3O" started.
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HLG2H0UTOJ3P" started.
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
      Connection id "0HLG2H0UTOJ3O" stopped.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[6]
      Connection id "0HLG2H0UTOJ3P" received FIN.
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
      Connection id "0HLG2H0UTOJ3Q" started.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
      Connection id "0HLG2H0UTOJ3P" sending FIN.
Connection = new HubConnectionBuilder()
            .WithUrl("https://foo:5001/barService")
            .Build();

if (Connection.State == HubConnectionState.Disconnected)
            {
                try
                {
                    await Connection.StartAsync();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

@davidfowl
Copy link
Member Author

I've tested the nightly versions a bit more, but it doesn't work the same like in the old SignalR

That's right, they work very differently.

In my case 3 time the state is disconnected and I start 3 connections not only 1 like in old SignalR.

Can you clarify what you mean? There's no intermediate states, there's disconnected and connected. There's no automatic reconnect either so when disconnected, you need to manually reconnect.

@MagicAndre1981
Copy link

In each method I call a Connect method which checks the State to check if the connection is already connected and if not I start the connection. this works fine for old SignalR and I only have 1 connection. Now for the first 3 calls the state is always disconnected and I have 3 connections from 1 client.

@davidfowl
Copy link
Member Author

Do you mean you have 3 different hubs?

@MagicAndre1981
Copy link

no, 1 hub like in old SignalR. I copied the old code and made some required changes to get it working with new SignalR (remove overloads for example)

@davidfowl
Copy link
Member Author

Can you provide a sample project with repro steps?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 - Done cost: S Will take up to 2 days to complete type: Enhancement
Projects
None yet
Development

No branches or pull requests

5 participants