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 StartAsync() CancellationToken not respected?

See original GitHub issue

Seems 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
BalintFarkascommented, May 9, 2019

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?

2reactions
mikaelm12commented, May 9, 2019

@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?

Read more comments on GitHub >

github_iconTop 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 >

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