Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignalR Client client-to-server streaming is memory leaking in ConnectionState.UploadStreamToken #50913

Closed
1 task done
higor-hernandes opened this issue Sep 25, 2023 · 2 comments · Fixed by #51117
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

Comments

@higor-hernandes
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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 of HubConnection.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.

image
image

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 the HubConnection.ReceiveLoop method

Client implementation of the how to reproduce:
image

Hub implementation of the how to reproduce:
image

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:
image
image

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Sep 25, 2023
@BrennanConroy BrennanConroy added the bug This issue describes a behavior which is not expected - a bug. label Oct 3, 2023
@BrennanConroy
Copy link
Member

Nice find! I am curious how you found it though.

@higor-hernandes
Copy link
Author

higor-hernandes commented Oct 4, 2023

Hello Brennan, thanks for looking into it.
We have a service that cannot be stopped frequently for maintenance. After a few weeks, we noticed an unusually high memory usage. We took memory snapshots and investigated until we reached the SignalR code.
We are looking forward to having this fixed.

@BrennanConroy BrennanConroy added this to the 7.0.13 milestone Oct 18, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-signalr Includes: SignalR clients and servers bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants