You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using signalR in an asp net core / angular 17 project and looking at the performance counters i noticed:
Average Connection Duration (ms)
0
Current Connections
218
Total Connections Started
303
Total Connections Stopped
85
Total Connections Timed Out
1
I restarted the server yesterday which means overnight i somehow ended up with 200+ connections which seems way too much:
We have about 10 employees using the webapp which uses signalR. Lets say each employee has on average 5 tabs open, coming to 50 connections.
We then have a dashboard web app which comes to another 1 connection, and the background processor which also has 1 connection. I can see the current connection counter go up and down when open or close a tab in the webapp.
200+ active connections seem too much - Am i forgetting some client-side cleanups somewhere or what would cause such a high connection count?
Some reference code
Webapp:
fnRetry=()=>Math.random()*(1000-350)+350;this.connection=newsignalR.HubConnectionBuilder().configureLogging(signalR.LogLevel.Warning).withUrl(environment.api.baseUrl.replace(/\/api$/,endpoint),{accessTokenFactory: ()=>authService.getAuthorization().token,skipNegotiation: true,transport: signalR.HttpTransportType.WebSockets}).withAutomaticReconnect({nextRetryDelayInMilliseconds: this.fnRetry// indefinite retry ever N ms}).build();this.connection.onclose((err)=>{if(err===undefined){return;// under normal operation.}console.error('Hub connection was closed',err);this.onConnectionChanged(false);// Restart when the server closes the requestthis.startConnectionSubscription=this.startHubconnection(this.connection,this.fnRetry).subscribe({complete: this.startConnectionSubscription=null});});this.connection.onreconnecting(()=>{this.onConnectionChanged(false);});this.connection.onreconnected(()=>{this.onConnectionChanged(true);});startHubconnection(connection: signalR.HubConnection,fnRetry: ()=>number){returndefer(()=>from(connection.start())).pipe(catchError((err)=>{this.onConnectionChanged(false);returnthrowError(()=>err);}),retry({delay(){returntimer(fnRetry());},}),// indefinite retry ever N mstap(()=>this.onConnectionChanged(true)));}
The c# client apps pretty much have the same setup:
services.AddTransient<IOrderHubClient,OrderHubClient>(c =>{vartokenManager=c.GetRequiredService<IOPGWebApiTokenManager>();returnActivatorUtilities.CreateInstance<OrderHubClient>(c,newHubConnectionBuilder().WithUrl(newUri(baseWebUrl+"/orderHub"), opt =>{opt.SkipNegotiation=true;opt.Transports=HttpTransportType.WebSockets;opt.AccessTokenProvider=()=>tokenManager.GetToken(CancellationToken.None)!;}).WithAutomaticReconnect().Build());});// Should be properly disposed (clients get created ad-hoc):// OrderHubClient
#region IDisposable
protectedvirtualvoidDispose(booldisposing){if(disposing){_subscription.Dispose();_cancellationTokenSource.Dispose();_=_connection.DisposeAsync().AsTask();}}/// <inheritdoc />publicvoidDispose(){Dispose(true);GC.SuppressFinalize(this);}protectedvirtualasyncValueTaskDisposeAsyncCore(){awaitCastAndDispose(_subscription);awaitCastAndDispose(_cancellationTokenSource);await_connection.DisposeAsync();return;staticasyncValueTaskCastAndDispose(IDisposableresource){if(resourceisIAsyncDisposableresourceAsyncDisposable)awaitresourceAsyncDisposable.DisposeAsync();elseresource.Dispose();}}/// <inheritdoc />publicasyncValueTaskDisposeAsync(){awaitDisposeAsyncCore();GC.SuppressFinalize(this);}
#endregion
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hiya,
I'm using signalR in an asp net core / angular 17 project and looking at the performance counters i noticed:
I restarted the server yesterday which means overnight i somehow ended up with 200+ connections which seems way too much:
We have about 10 employees using the webapp which uses signalR. Lets say each employee has on average 5 tabs open, coming to 50 connections.
We then have a dashboard web app which comes to another 1 connection, and the background processor which also has 1 connection. I can see the current connection counter go up and down when open or close a tab in the webapp.
200+ active connections seem too much - Am i forgetting some client-side cleanups somewhere or what would cause such a high connection count?
Some reference code
Webapp:
The c# client apps pretty much have the same setup:
Beta Was this translation helpful? Give feedback.
All reactions