Runtime.Tests flake: GrpcDataLateWriteTests.Reserved_observer_records_actual_late_result_and_releases_owned_lifetime — observes lifetime before the slot release #964

Closed
opened 2026-12-01 21:31:16 -05:00 by dohertj2 · 1 comment
Owner

Seen 2026-12-01 in the #962 repro loop (full FullyQualifiedName~DataConnections&Category!=SlowUnit filter, 3 parallel lanes, host load ~60): 1 failure in the before-loop.

Shouldly.ShouldAssertException : observer.TryReserve(out var next) should be True but was False
  at GrpcDataLateWriteTests.Reserved_observer_records_actual_late_result_and_releases_owned_lifetime() GrpcDataLateWriteTests.cs:line 38

Cause (read from the code, test-side timing): LateWriteReservation.ObserveCore's finally runs claim.PhysicalFinished(), then lifetime?.Dispose(), then _owner.Release(this, _target). The test waits WaitUntil(() => claim.CurrentOutcome == Success && lifetime.Count == 1) and then immediately calls observer.TryReserve, so it can run between the lifetime dispose and the slot release. The production order (lifetime released before the physical slot) looks intentional; the test is waiting on the wrong signal.

Fix suggestion: wait for the slot itself (e.g. WaitUntil(() => observer.TryReserve(out var r) && Dispose(r)), or expose an outstanding count) instead of the lifetime counter. Same pattern may affect Expired_observer_retains_physical_capacity_and_lifetime_until_driver_really_finishes and Already_completed_driver_is_observed_and_reservation_dispose_is_idempotent (both wait on lifetime.Count == 1 then TryReserve).

Found while working #962; out of scope there.

Seen 2026-12-01 in the #962 repro loop (full `FullyQualifiedName~DataConnections&Category!=SlowUnit` filter, 3 parallel lanes, host load ~60): 1 failure in the before-loop. ``` Shouldly.ShouldAssertException : observer.TryReserve(out var next) should be True but was False at GrpcDataLateWriteTests.Reserved_observer_records_actual_late_result_and_releases_owned_lifetime() GrpcDataLateWriteTests.cs:line 38 ``` Cause (read from the code, test-side timing): `LateWriteReservation.ObserveCore`'s `finally` runs `claim.PhysicalFinished()`, then `lifetime?.Dispose()`, then `_owner.Release(this, _target)`. The test waits `WaitUntil(() => claim.CurrentOutcome == Success && lifetime.Count == 1)` and then immediately calls `observer.TryReserve`, so it can run between the lifetime dispose and the slot release. The production order (lifetime released before the physical slot) looks intentional; the test is waiting on the wrong signal. Fix suggestion: wait for the slot itself (e.g. `WaitUntil(() => observer.TryReserve(out var r) && Dispose(r))`, or expose an outstanding count) instead of the lifetime counter. Same pattern may affect `Expired_observer_retains_physical_capacity_and_lifetime_until_driver_really_finishes` and `Already_completed_driver_is_observed_and_reservation_dispose_is_idempotent` (both wait on `lifetime.Count == 1` then `TryReserve`). Found while working #962; out of scope there.
dohertj2 added the type:testpriority:p3 labels 2026-12-01 21:31:16 -05:00
Author
Owner

Fixed in bcd4a9aa2 (merged 7c4a070cc). Real production race: the write reply/WriteCompleted ran on a different continuation from LateWriteReservation's slot release, so the next same-tag write could be falsely rejected as capacity exhausted. Observe now returns a Task that RunRichWriteAsync awaits when the physical write completed. Actor repro failed 3/3 before and passes 15/15 under heavy load after; the unit loop went from 22–39 false rejections per 2M iterations to 0. Follow-up: #967.

Fixed in bcd4a9aa2 (merged 7c4a070cc). Real production race: the write reply/WriteCompleted ran on a different continuation from LateWriteReservation's slot release, so the next same-tag write could be falsely rejected as capacity exhausted. Observe now returns a Task that RunRichWriteAsync awaits when the physical write completed. Actor repro failed 3/3 before and passes 15/15 under heavy load after; the unit loop went from 22–39 false rejections per 2M iterations to 0. Follow-up: #967.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#964