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
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:
1 parent
af67a1757a
commit
938adbf3a8
2 files changed
+56
-14
No files matched your search
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: signalr-client-lifecycle
|
||||
description: Avoid blocking SignalR client teardown in Heimdall Blazor components and services.
|
||||
---
|
||||
|
||||
# Heimdall SignalR client lifecycle
|
||||
|
||||
`NotificationsHubClient` is scoped to a Blazor circuit and owns a `HubConnection`. Components that use it should implement `IAsyncDisposable`, unsubscribe their event handlers, then await `Hub.DisposeAsync()`.
|
||||
|
||||
## Implementation
|
||||
|
||||
- Do not call `.Wait()`, `.Result`, or `GetAwaiter().GetResult()` on SignalR stop/dispose operations. Network shutdown can block a renderer or request thread.
|
||||
- Centralize teardown in one asynchronous helper. Atomically detach the owned connection before awaiting shutdown so repeated disposal cannot dispose it twice.
|
||||
- `DisposeAsync()` awaits `StopAsync` and `DisposeAsync`, handling shutdown failures independently so failed stop still attempts resource disposal.
|
||||
- If compatibility requires synchronous `IDisposable`, it must return without blocking and start best-effort asynchronous cleanup. Keep `GC.SuppressFinalize(this)` on both dispose paths.
|
||||
- Log cleanup failures at debug level without access tokens, URLs containing credentials, or message payloads.
|
||||
|
||||
## Acceptance
|
||||
|
||||
1. Build `src/Heimdall.Web/Heimdall.Web.csproj` with the SDK pinned by `global.json`; do not suppress analyzer warnings for blocking calls.
|
||||
2. Verify the component unsubscribes handlers and awaits async disposal.
|
||||
3. Run the disposable Central + PostgreSQL Compose recipe from `skills/compose-disposable-recipe/SKILL.md` with unique generated credentials, ports, project, and image tag; check `/healthz` and verify cleanup of project resources and that exact tag.
|
||||
4. Treat production GlitchTip recurrence as external evidence: local build and Compose do not prove the deployed client has stopped emitting events.
|
||||
|
||||
See Gitea issue [#233](https://sources.tordais.cc/arnaud.dartois/Heimdall/issues/233) for the current incident evidence.
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user