SignalR Client client-to-server streaming is memory leaking in ConnectionState.UploadStreamToken #50913
Closed
1 task done
Labels
area-signalr
Includes: SignalR clients and servers
bug
This issue describes a behavior which is not expected - a bug.
Milestone
Is there an existing issue for this?
Describe the bug
When using ASP.NET Core SignalR Client to stream data from client to server, the HubConnection is memory leaking CancellationToken Callbacks in the CancellationTokenSource of the
ConnectionState.UploadStreamToken
. For each call ofHubConnection.SendAsync
it registers a new CancellationToken Callback in this CancellationTokenSource and does not remove it after completing the upload. I don’t know if it is just a missuse of the SignalR client or it really has a memory leak while uploading streams.Expected Behavior
Does not indefinitely increase memory usage when sending a ChannelReader in the HubConnection.SendAsync. Unregister the cancellation callbacks after completing each SendAsync request.
Steps To Reproduce
Keep uploading data using the HubConnection.SendAsync and Channels
For each call of the SendAsync it leaks in the CancellationTokenSource described.
repo: https://github.com/higor-hernandes/signalr-sample-tests
build and run the SignalRHubSample project.
build and run the SignalRHubClientSample project.
In a few seconds is possible to see the CancellationToken Callbacks being register and accumulating in the CancellationTokenSource from
ConnectionState.UploadStreamToken
created in theHubConnection.ReceiveLoop
methodClient implementation of the how to reproduce:

Hub implementation of the how to reproduce:

Exceptions (if any)
No response
.NET Version
7.0.202
Anything else?
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.5.3
.NET SDK:
Version: 7.0.202
Commit: 6c74320bc3
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.202
Host:
Version: 7.0.4
Architecture: x64
Commit: 0a396acafe
.NET SDKs installed:
7.0.202 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Client Sample Packages:
Microsoft.AspNetCore.SignalR.Client 7.0.11
Hub Sample Packages:
Microsoft.AspNetCore.SignalR.Protocols.Json 7.0.11
Where in SignalR Client the leak might be coming from:


The text was updated successfully, but these errors were encountered: