diff --git a/src/RemoteViewer.Server/Orleans/Grains/ConnectionGrain.cs b/src/RemoteViewer.Server/Orleans/Grains/ConnectionGrain.cs index 5a9b382..452f637 100644 --- a/src/RemoteViewer.Server/Orleans/Grains/ConnectionGrain.cs +++ b/src/RemoteViewer.Server/Orleans/Grains/ConnectionGrain.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.SignalR; using RemoteViewer.Server.Hubs; using RemoteViewer.Shared; @@ -28,7 +28,9 @@ public sealed partial class ConnectionGrain(ILogger logger, IHu public async Task UpdateProperties(string signalrConnectionId, ConnectionProperties properties) { - if (this._presenter?.GetPrimaryKeyString() != signalrConnectionId) + this.EnsureInitialized(); + + if (this._presenter.GetPrimaryKeyString() != signalrConnectionId) { this.LogNonPresenterUpdateAttempt(signalrConnectionId, this.GetPrimaryKeyString()); return; @@ -149,6 +151,8 @@ await hubContext.Clients } async Task IConnectionGrain.Internal_AddViewer(IClientGrain viewer) { + this.EnsureInitialized(); + if (this._viewers.Contains(viewer)) { this.LogViewerAlreadyInConnection(this.GetPrimaryKeyString(), viewer.GetPrimaryKeyString()); @@ -190,11 +194,17 @@ async Task IConnectionGrain.Internal_RemoveClient(IClientGrain client) await hubContext.Clients.Client(client.GetPrimaryKeyString()).ConnectionStopped(this.GetPrimaryKeyString()); - await this.NotifyConnectionChangedAsync(); + // Only notify if presenter still exists - during teardown the presenter may have already + // disconnected and nullified _presenter, so we skip notification since the connection is dead + if (this._presenter is not null) + { + await this.NotifyConnectionChangedAsync(); + } } } async Task IConnectionGrain.Internal_DisplayNameChanged() { + this.EnsureInitialized(); await this.NotifyConnectionChangedAsync(); } diff --git a/src/RemoteViewer.Server/Program.cs b/src/RemoteViewer.Server/Program.cs index 7364f18..65bf36a 100644 --- a/src/RemoteViewer.Server/Program.cs +++ b/src/RemoteViewer.Server/Program.cs @@ -1,4 +1,4 @@ -using Nerdbank.MessagePack.SignalR; +using Nerdbank.MessagePack.SignalR; using RemoteViewer.Server.Hubs; using RemoteViewer.Server.Services; using RemoteViewer.Shared; @@ -26,9 +26,6 @@ .AddSignalR(options => { options.MaximumReceiveMessageSize = null; - - options.ClientTimeoutInterval = TimeSpan.FromMinutes(2); - options.KeepAliveInterval = TimeSpan.FromSeconds(30); }) .AddMessagePackProtocol(Witness.GeneratedTypeShapeProvider); builder.Services.AddSerilog();