SignalR Core StartAsync() CancellationToken not respected?
See original GitHub issueSeems that the AspNetCore Signalr Client doesn’t respect the cancellationtoken passed into the StartAsync() method. It will throw appropriately if the CTS timeout is sufficiently short (e.g., 1 millisecond);
Using this version of ASP.NET Core 3 Preview 5
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
var _hubConnection = new HubConnectionBuilder()
.WithUrl(".WithUrl("http://slowwly.robertomurray.co.uk/delay/5000/url/http://www.google.co.uk")") //artificially slow, response times of ~5 seconds before a 404 is returned
.Build();
await _hubConnection.StartAsync(cts.Token);
Expected behavior
StartAsync() should throw an OperationCancelledException after 1 second. Any negotiation or handshake should be aborted if it was not already successfully completed within 1 second.
Current behavior
StartAsync() will wait until an HttpRequestException (in this case, a 404 after 5 seconds) is thrown or the connection succeeds. An OperationCancelledException is never thrown.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10 (10 by maintainers)
Top Results From Across the Web
SignalR Core StartAsync() CancellationToken not respected?
After invoke the canselationtokensource.cancel() nothing happens. StartAsync() will wait until an Timeout is thrown or the connection succeeds.
Read more >SignalR: Cancellation in Case of Client to Server ...
Why in the case of using the cancellation token in hub method signature, it doesn't work? (seems it cancels just right after calling...
Read more >HubConnection.StartAsync(CancellationToken) Method
A Task that represents the asynchronous start. Applies to. Product, Versions. ASP.NET Core, 2.1, 2.2, 3.0, 3.1, ...
Read more >Bring Your Apps to Life With SignalR and .NET 6
NET Core has a technology called SignalR. In this article, we will get an introduction to SignalR and create a simple example that...
Read more >SignalR on .NET 6 - the Complete Guide
The suggested tweet for this book is: Here is the complete guide on using SignalR on .NET 6! The suggested hashtag for this...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hey @mikaelm12 -
sure, we’d be delighted to! We have already created fixes for 1.1.0 and 1.0.4, and will create one for the current 3.x version tomorrow with my colleague @danielloczi, then submit PRs. Would that be acceptable?
@BalintFarkas Since you already have the fix in your fork this issue seems like a great candidate for a community contribution 😄 . Would you be interested?