fix(web): avoid blocking SignalR disposal
Heimdall Gitea / Detect CI scope (push) Successful in 19s
Heimdall Gitea / Build and tests (push) Successful in 18m10s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 5m20s
Heimdall Gitea / Build and scan agent image (push) Successful in 9m26s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m19s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 16m17s
Heimdall Gitea / CI policy (push) Successful in 2s

Fixes blocking SignalR client shutdown; see issue #233.

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
This commit was merged in pull request #272.
This commit is contained in:
arnaud.dartois authored and Arnaud Dartois committed 2026-11-06 20:55:07 +01:00
1 parent af67a1757a
commit 938adbf3a8
2 files changed
+56 -14

No files matched your search

@@ -104,25 +104,42 @@ public class NotificationsHubClient : IAsyncDisposable, IDisposable
public void Dispose()
{
// Dispose synchrone (requis par certains conteneurs / bUnit) :
// déconnexion best-effort sans attendre la fermeture réseau.
if (_connection is not null)
{
try
{
_connection.StopAsync(CancellationToken.None).Wait(TimeSpan.FromMilliseconds(500));
_connection.DisposeAsync().AsTask().GetAwaiter().GetResult();
}
catch { /* best effort */ }
}
_started = false;
// Synchronous disposal cannot safely wait for SignalR network shutdown.
// Start the asynchronous cleanup and return immediately; async consumers
// should use DisposeAsync to observe its completion.
_ = DisposeConnectionAsync();
GC.SuppressFinalize(this);
}
public async ValueTask DisposeAsync()
{
Dispose();
await DisposeConnectionAsync().ConfigureAwait(false);
GC.SuppressFinalize(this);
await Task.CompletedTask;
}
private async Task DisposeConnectionAsync()
{
var connection = Interlocked.Exchange(ref _connection, null);
_started = false;
if (connection is null)
return;
try
{
await connection.StopAsync(CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogDebug(ex, "NotificationsHubClient: arrêt de la connexion impossible");
}
try
{
await connection.DisposeAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogDebug(ex, "NotificationsHubClient: libération de la connexion impossible");
}
}
}