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 Stream is will throw when combined with ToObservable from IX.net, and the stream completes.

See original GitHub issue
public class FooHub : Hub
{
    public IAsyncEnumerable<int> Foo()
    {
        return AsyncEnumerable.Empty<int>();
    }
}

public static class Program
{
    public async Task Main()
    {
         await new HubConnectionBuilder()
              .WithUrl(....)
             .Build()
             .StreamAsync(nameof(FooHub.Foo))
             .ToObservable()
            .Do(x => Console.WriteLine(x))
            .ToTask();
    }
}

This will throw an exception of CancellationTokenSource ObjectDisposedException.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Dec 7, 2020

Minimal repro without IX.net

var asyncEnumerable = connection.StreamAsyncCore<int>("Stream", new object[] { streamTo });
using var cts = new CancellationTokenSource();
await using var e = asyncEnumerable.GetAsyncEnumerator(cts.Token);
while (await e.MoveNextAsync())
{
}
cts.Cancel();

The issue is that we dispose an internal cts when the server sends a stream completion https://github.com/dotnet/aspnetcore/blob/b4f8e0f587c064b67b99e7ee5f1562fc61ba9242/src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs#L579

Then, if the user cancels a token passed into GetAsyncEnumerator before the enumerator is disposed we will try to cancel the disposed cts from earlier https://github.com/dotnet/aspnetcore/blob/b4f8e0f587c064b67b99e7ee5f1562fc61ba9242/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs#L69

0reactions
msftbot[bot]commented, Dec 4, 2020

Thanks for contacting us. We’re moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use streaming in ASP.NET Core SignalR
To end the stream from the client, call the dispose method on the ISubscription that's returned from the subscribe method. Calling this method ......
Read more >
How to correctly dispose a client stream if the connection ...
I'm using Microsoft.AspNetCore.SignalR 2.1 v1.0.4 and have a ChannelReader stream being consumed by a typescript client using v1.0.4. The ...
Read more >
Intro to SignalR in C# Part 1 - using Blazor, WPF ... - YouTube
SignalR is an excellent way to connect two or more clients together for real-time communication. The best part is that this library is...
Read more >
Quick Introduction to SignalR Streaming - YouTube
Streaming is a brand new feature in SignalR that isn't commonly talked about. It can help you more efficiently send data from your...
Read more >
Streaming in SignalR - Scientific Programmer
SignalR can stream from the client to the server and from the server to the client. We will have a look at both,...
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