diff --git a/docs/Sessions.md b/docs/Sessions.md index f00fc956..b2b3e86d 100644 --- a/docs/Sessions.md +++ b/docs/Sessions.md @@ -62,7 +62,7 @@ Tags gate **visibility only**: which sessions' event metadata a dashboard user m `CloseSessionAsync` and `KillWorkerAsync` are both end-of-life paths but differ in what they offer the worker: - `CloseSessionAsync` is the graceful path: it calls `GatewaySession.CloseAsync`, which asks the worker to shut down via `IWorkerClient.ShutdownAsync` and only kills the process as a fallback if shutdown fails. -- `KillWorkerAsync` is the forceful path used by the dashboard's admin Kill button: it calls `GatewaySession.KillWorker` directly, which kills the worker process immediately with no graceful-shutdown attempt and transitions the session to `Closed`. +- `KillWorkerAsync` is the forceful path used by the dashboard's admin Kill button: it calls `GatewaySession.KillWorkerWithCloseGateAsync`, which takes the per-session close gate (so it serializes with a concurrent `CloseAsync`), kills the worker process immediately with no graceful-shutdown attempt, and transitions the session to `Closed`. There is no ungated kill primitive on `GatewaySession`. Both paths converge on the same registry/metrics cleanup, so the open-session slot is released and `mxgateway.sessions.closed` is incremented either way. diff --git a/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs b/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs index e723dd1d..29a5653d 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs @@ -11,7 +11,7 @@ using ZB.MOM.WW.MxGateway.Server.Workers; namespace ZB.MOM.WW.MxGateway.Server.Sessions; -public sealed class GatewaySession +public sealed class GatewaySession : IAsyncDisposable { // Shared untagged sentinel: most sessions carry no dashboard tags. Frozen so the exposed set // cannot be mutated by a cast — the tag set is a visibility grant, not a scratch collection. @@ -2050,16 +2050,6 @@ public sealed class GatewaySession } } - /// - /// Terminates the worker process immediately. - /// - /// Reason for killing the worker. - public void KillWorker(string reason) - { - _workerClient?.Kill(reason); - TransitionTo(SessionState.Closed); - } - /// /// Terminates the worker process immediately while holding the per-session /// close lock so concurrent close/kill callers serialize. Returns the diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/GatewaySessionTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/GatewaySessionTests.cs index 23c9aa15..f9e5b97b 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/GatewaySessionTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/GatewaySessionTests.cs @@ -19,6 +19,26 @@ namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Sessions; /// public sealed class GatewaySessionTests { + /// + /// owns async teardown (DisposeAsync) and must + /// advertise it through (mxaccessgw#191): a holder that + /// stores it as , or a DI container disposing what it + /// tracks, only finds the teardown through the interface — pattern-based + /// await using alone hides that from them. + /// + /// A task that represents the asynchronous operation. + [Fact] + public async Task GatewaySession_ImplementsIAsyncDisposable() + { + FakeWorkerClient workerClient = new(); + object session = CreateReadySession(workerClient); + + IAsyncDisposable disposable = Assert.IsAssignableFrom(session); + await disposable.DisposeAsync(); + + Assert.Equal(1, workerClient.DisposeCount); + } + /// /// A TransitionTo(Ready) issued after /// has set diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionManagerTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionManagerTests.cs index 278059d2..dddfb29c 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionManagerTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionManagerTests.cs @@ -814,7 +814,7 @@ public sealed class SessionManagerTests /// /// Verifies that killing a worker removes the session from the registry without calling shutdown. /// Also pins the reason argument propagating through - /// SessionManager.KillWorkerAsync → session.KillWorker(reason) + /// SessionManager.KillWorkerAsync → session.KillWorkerWithCloseGateAsync(reason, ct) /// → IWorkerClient.Kill(reason). /// /// A task that represents the asynchronous operation. @@ -896,7 +896,7 @@ public sealed class SessionManagerTests } /// - /// When session.KillWorker throws, the catch path must still + /// When session.KillWorkerWithCloseGateAsync throws, the catch path must still /// decrement mxgateway.sessions.open. Without the fix the gauge leaks one open session per failed kill. /// /// A task that represents the asynchronous operation. @@ -1035,7 +1035,7 @@ public sealed class SessionManagerTests /// /// ShutdownAsync's graceful-close fallback (which calls - /// KillWorker + RemoveSessionAsync when CloseSessionCoreAsync throws) + /// KillWorkerAsync + RemoveSessionAsync when CloseSessionCoreAsync throws) /// must still account a successful close: both the open-session gauge must drop to zero AND /// the mxgateway.sessions.closed counter must increment. Without the fix, the /// graceful-close failure path under-counts the closed counter. Both the shutdown and the @@ -2235,7 +2235,7 @@ public sealed class SessionManagerTests /// /// Gets the last reason argument observed by . Pins the /// reason-string propagation through SessionManager.KillWorkerAsync - /// → session.KillWorker(reason) → IWorkerClient.Kill(reason); + /// → session.KillWorkerWithCloseGateAsync(reason, ct) → IWorkerClient.Kill(reason); /// without this, the chain could silently drop or substitute the reason /// argument and existing tests would still pass. ///