Rich write: invoker failing before the dispatch delegate on an externally-rejected claim leaks the late-write slot and target forever #967

Closed
opened 2026-12-02 13:09:57 -05:00 by dohertj2 · 1 comment
Owner

Found while reviewing #964 (read from code, not reproduced).

DriverInstanceActor.RunRichWriteAsync (src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverInstanceActor.cs) hands the late-write reservation to physical.Task via reservation.Observe(...) BEFORE the invoker runs. physical is completed only by the dispatch delegate, the driver observers, or the catch paths. In the Task.Run catch (the invoker threw, e.g. an open circuit breaker / bulkhead rejection, without ever calling the delegate):

var outcome = msg.Claim.Complete(RichRejected) ? RichRejected : RichUnknown;
if (outcome == RichRejected) physical.TrySetResult(outcome);
else msg.Claim.Complete(outcome);

If the claim was already completed undispatched by someone else (state 4 — e.g. an external pre-dispatch deadline, as GrpcDataDriverOutcomeTests line ~226 does), Complete(RichRejected) returns false, the branch picks RichUnknown, and physical is never completed. Nothing was ever sent to the driver, but LateWriteObserver.ObserveCore awaits physical.Task forever: the global outstanding slot and the (driver, reference) target stay reserved for the process lifetime, so every later rich write to that tag is rejected with "Outstanding driver write capacity exhausted" (and the ticket's byte lease is never released).

The outer WaitAsync timeout catch has the same shape.

Suggested fix: when the claim is not dispatched (!msg.Claim.IsDispatched / IsCompletedUndispatched), complete physical with the claim's terminal outcome regardless of who completed it — the same rule the request-building catch already uses (if (!msg.Claim.IsDispatched) physical.TrySetResult(noCall)). Needs a red test: externally complete the claim as RejectedBeforeDispatch, make the invoker throw without calling the delegate, then assert a second write to the same target is not rejected.

Found while reviewing #964 (read from code, not reproduced). `DriverInstanceActor.RunRichWriteAsync` (src/Server/ZB.MOM.WW.OtOpcUa.Runtime/Drivers/DriverInstanceActor.cs) hands the late-write reservation to `physical.Task` via `reservation.Observe(...)` BEFORE the invoker runs. `physical` is completed only by the dispatch delegate, the driver observers, or the catch paths. In the `Task.Run` catch (the invoker threw, e.g. an open circuit breaker / bulkhead rejection, without ever calling the delegate): ```csharp var outcome = msg.Claim.Complete(RichRejected) ? RichRejected : RichUnknown; if (outcome == RichRejected) physical.TrySetResult(outcome); else msg.Claim.Complete(outcome); ``` If the claim was already completed **undispatched** by someone else (state 4 — e.g. an external pre-dispatch deadline, as `GrpcDataDriverOutcomeTests` line ~226 does), `Complete(RichRejected)` returns false, the branch picks `RichUnknown`, and `physical` is never completed. Nothing was ever sent to the driver, but `LateWriteObserver.ObserveCore` awaits `physical.Task` forever: the global outstanding slot and the `(driver, reference)` target stay reserved for the process lifetime, so every later rich write to that tag is rejected with "Outstanding driver write capacity exhausted" (and the ticket's byte lease is never released). The outer `WaitAsync` timeout catch has the same shape. Suggested fix: when the claim is not dispatched (`!msg.Claim.IsDispatched` / `IsCompletedUndispatched`), complete `physical` with the claim's terminal outcome regardless of who completed it — the same rule the request-building catch already uses (`if (!msg.Claim.IsDispatched) physical.TrySetResult(noCall)`). Needs a red test: externally complete the claim as RejectedBeforeDispatch, make the invoker throw without calling the delegate, then assert a second write to the same target is not rejected.
dohertj2 added the type:bugpriority:p2 labels 2026-12-02 13:09:57 -05:00
Author
Owner

Fixed in 8d6b64393 (merged 8e0399530). Both RunRichWriteAsync catch paths go through FailRichAttempt: a claim that was never dispatched completes the physical task with its pre-dispatch outcome, which releases the slot, target and lease, and replies RejectedBeforeDispatch. Only a claim that was actually dispatched still waits for the driver and replies OutcomeUnknown. The regression test failed on both halves before the fix. DataConnections+DriverInstanceActor 1126/1126, Host GrpcData 210/210.

Fixed in 8d6b64393 (merged 8e0399530). Both RunRichWriteAsync catch paths go through FailRichAttempt: a claim that was never dispatched completes the physical task with its pre-dispatch outcome, which releases the slot, target and lease, and replies RejectedBeforeDispatch. Only a claim that was actually dispatched still waits for the driver and replies OutcomeUnknown. The regression test failed on both halves before the fix. DataConnections+DriverInstanceActor 1126/1126, Host GrpcData 210/210.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#967