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 am using the SignalR JS client with Azure SignalR Service (Serverless). I would like to be able to support multiple resources for resiliency (it would be nice if this was available as a standard feature!), so I provide my client with a SignalRConnectionInfo object for each resource. My client can then automatically switch to another resource if it encounters an error with the first one it tries.
When this happens, I want to reassign my HubConnection object with a new instance, but I'm worried that this might leak event handlers - I can call the off methods to unbind my own event handlers, but there is no equivalent for the onclose method.
I've included a simplified example of my setup and connection functions
privateasyncsetupConnection(connectionInfo: SignalrConnectionInfo){constoptions={accessTokenFactory: ()=>connectionInfo.accessToken};this.connection=newHubConnectionBuilder().withUrl(connectionInfo.url,options).build();this.connection.on('message',(data: any)=>{// do stuff});this.connection.onclose(async(err)=>{setTimeout(()=>this.tryNextConnection(),5000);});}privateasyncconnect(){try{awaitthis.connection.start();}catch(err){setTimeout(()=>this.tryNextConnection(),5000);}}
The tryNextConnection method will call setupConnection with a different connectionInfo object and attempt a new connection to the 'next' resource. If there are no other connectionInfo objects to try, it will reuse the same details as before.
The more times a connection attempt fails, the more HubConnections it would create, which is why I'm concerned about leaking handlers. Looking at the C# client, I assume I would be able to unbind the closed handler using connection.Closed -= ... so is there any reason we couldn't do this in the JS client?
Also, are there any plans to support multiple serverless resources natively?
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
-
I am using the SignalR JS client with Azure SignalR Service (Serverless). I would like to be able to support multiple resources for resiliency (it would be nice if this was available as a standard feature!), so I provide my client with a SignalRConnectionInfo object for each resource. My client can then automatically switch to another resource if it encounters an error with the first one it tries.
When this happens, I want to reassign my
HubConnection
object with a new instance, but I'm worried that this might leak event handlers - I can call theoff
methods to unbind my own event handlers, but there is no equivalent for theonclose
method.I've included a simplified example of my setup and connection functions
The
tryNextConnection
method will callsetupConnection
with a different connectionInfo object and attempt a new connection to the 'next' resource. If there are no other connectionInfo objects to try, it will reuse the same details as before.The more times a connection attempt fails, the more HubConnections it would create, which is why I'm concerned about leaking handlers. Looking at the C# client, I assume I would be able to unbind the closed handler using
connection.Closed -= ...
so is there any reason we couldn't do this in the JS client?Also, are there any plans to support multiple serverless resources natively?
Beta Was this translation helpful? Give feedback.
All reactions