Skip to content

Commit

Permalink
Dispose of SignalR connections created by HTTP proxy (#329)
Browse files Browse the repository at this point in the history
* Make compatibility level optional

CompatibilityLevel is deprecated, so make it optional in all AdapterSignalRClient constructors.

* Hub connection should be disposed

Specify that AdapterSignalRClients created by HttpAdapterProxy should dispose of their HubConnections when disposed.

* Update public API
  • Loading branch information
wazzamatazz authored May 30, 2023
1 parent 4e63131 commit 1afaf74
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public event Func<Exception, Task> Closed {
/// <exception cref="ArgumentNullException">
/// <paramref name="hubConnection"/> is <see langword="null"/>.
/// </exception>
public AdapterSignalRClient(HubConnection hubConnection, bool disposeConnection, CompatibilityLevel compatibilityLevel) {
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
public AdapterSignalRClient(HubConnection hubConnection, bool disposeConnection, CompatibilityLevel compatibilityLevel = CompatibilityLevel.Latest) {
_hubConnection = hubConnection ?? throw new ArgumentNullException(nameof(hubConnection));
_disposeConnection = disposeConnection;
CompatibilityLevel = compatibilityLevel;
Expand All @@ -196,6 +197,7 @@ public AdapterSignalRClient(HubConnection hubConnection, bool disposeConnection,

Closed += OnClosedAsync;
}
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.DefaultHubRoute = "/signalr/app-store-connect/v2.0" -> string!
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.Adapters.get -> DataCore.Adapter.AspNetCore.SignalR.Client.Clients.AdaptersClient!
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.AdapterSignalRClient(Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, bool disposeConnection, DataCore.Adapter.AspNetCore.SignalR.Client.CompatibilityLevel compatibilityLevel) -> void
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.AdapterSignalRClient(Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, DataCore.Adapter.AspNetCore.SignalR.Client.CompatibilityLevel compatibilityLevel = DataCore.Adapter.AspNetCore.SignalR.Client.CompatibilityLevel.AspNetCore3) -> void
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.AssetModel.get -> DataCore.Adapter.AspNetCore.SignalR.Client.Clients.AssetModelBrowserClient!
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.Closed -> System.Func<System.Exception!, System.Threading.Tasks.Task!>!
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
DataCore.Adapter.AspNetCore.SignalR.Client.AdapterSignalRClient.AdapterSignalRClient(Microsoft.AspNetCore.SignalR.Client.HubConnection! hubConnection, bool disposeConnection, DataCore.Adapter.AspNetCore.SignalR.Client.CompatibilityLevel compatibilityLevel = DataCore.Adapter.AspNetCore.SignalR.Client.CompatibilityLevel.AspNetCore3) -> void
2 changes: 1 addition & 1 deletion src/DataCore.Adapter.Http.Proxy/HttpAdapterProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal SignalRClientWrapper GetSignalRClient(IAdapterCallContext context) {
return _signalRClients.GetOrAdd(key, k => {
var client = new SignalRClientWrapper(
k,
new AspNetCore.SignalR.Client.AdapterSignalRClient(Options.SignalROptions!.ConnectionFactory.Invoke(new Uri(_client.HttpClient.BaseAddress, AspNetCore.SignalR.Client.AdapterSignalRClient.DefaultHubRoute), context)),
new AspNetCore.SignalR.Client.AdapterSignalRClient(Options.SignalROptions!.ConnectionFactory.Invoke(new Uri(_client.HttpClient.BaseAddress, AspNetCore.SignalR.Client.AdapterSignalRClient.DefaultHubRoute), context), true),
Options.SignalROptions.TimeToLive <= TimeSpan.Zero
? TimeSpan.FromSeconds(30)
: Options.SignalROptions.TimeToLive
Expand Down

0 comments on commit 1afaf74

Please sign in to comment.