From cb5250facea4921d7f7c9e33ff1f81ceda057f41 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 4 Dec 2026 15:40:40 -0500 Subject: [PATCH] =?UTF-8?q?test(script-worker):=20#1092=20the=20two=20"slo?= =?UTF-8?q?w=20caller=20does=20not=20starve=20the=20reader"=20tests=20use?= =?UTF-8?q?=20a=201.5=20s=20silence=20limit=20(3.5=20s=20block)=20?= =?UTF-8?q?=E2=80=94=20measured=20worker-side=20whole-process=20stalls,=20?= =?UTF-8?q?not=20heartbeat=20starvation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SupervisionTests.A_caller_that_blocks_after_its_result_does_not_starve_the_reader and its WorkerSoftClockTests sibling killed a healthy worker for "sent nothing for ~344 ms" at a 300 ms limit (3 x 100 ms) on a loaded macOS box. Investigated before loosening, with send-stamped heartbeats (temporary instrumentation, not committed): - the late beats were late at the WORKER (290-380 ms between sends, 1-150 ms transit), mid run, not during startup; - a cold worker beat every 100 +/- 8 ms from its first beat in 50 isolated runs at load 60-200, with and without 28 CPU burners, and in full-suite runs under 40 burners, with the heartbeat on the thread pool or on a dedicated thread alike (A/B) — no JIT / Roslyn / pool-injection starvation to fix; - the stalls appeared only in a full-suite run under the real load of other agents, with the box 24 of 25.6 GB into swap: whole-process stalls no worker change removes. So the tests take a 1.5 s limit (production: 3 s) and block the caller 3.5 s. Mutation still caught: with callers resumed inline on the reader both fail (the Supervision test by the heartbeat kill itself). 20/20 runs of the pair pass. --- .../SupervisionTests.cs | 19 ++++++++++++++--- .../WorkerSoftClockTests.cs | 21 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/SupervisionTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/SupervisionTests.cs index 1fdceb1d3..9ef339c0e 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/SupervisionTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/SupervisionTests.cs @@ -546,11 +546,23 @@ public sealed class SupervisionTests /// /// lmxopcua#789: callers resume on the connection's result dispatcher, never on the pipe reader — so a consumer /// that blocks after its await (the Calculation pump publishes to OPC UA subscribers there) cannot stop the reader - /// from taking heartbeats and get a healthy worker killed for silence. Here a 100 ms heartbeat (kill after 300 ms - /// of silence) and a continuation that blocks for 1.5 s. Mutation check: resume callers inline on the reader (a + /// from taking heartbeats and get a healthy worker killed for silence. Here a 100 ms heartbeat (kill after 1.5 s + /// of silence) and a continuation that blocks for 3.5 s. Mutation check: resume callers inline on the reader (a /// synchronous-continuation TaskCompletionSource completed by the reader, no dispatcher) and the worker is killed /// (KilledHeartbeat). /// + /// + /// lmxopcua#1092: the limit used to be three 100 ms intervals (300 ms), and this pair of tests failed + /// intermittently on a loaded macOS dev box (about 1 full-suite run in 3–5), the worker killed for "sent nothing + /// for 344 ms" while the reader and the dispatcher worked correctly. Measured with send-stamped heartbeats: the + /// WORKER sent a beat 290–380 ms late (1–150 ms in transit), mid-run, not at startup — a cold worker beat every + /// 100 ± 8 ms from its first beat in 50 isolated runs at load 60–200, with and without 28 CPU burners, and no + /// run outside that real-load full suite (24 of 25.6 GB into swap at the time) stalled at all, whether the + /// heartbeat ran on the thread pool or on a dedicated thread. Those are whole-process stalls of the box, not + /// starvation a worker change can remove. So the limit is 1.5 s (production's is 3 s) and the block 3.5 s: a + /// reader held by the caller still goes silent 2 s past the limit, so the mutation is still killed, and the + /// resumedOn assertion pins the thread outright. + /// [Fact] public async Task A_caller_that_blocks_after_its_result_does_not_starve_the_reader() { @@ -558,6 +570,7 @@ public sealed class SupervisionTests var heartbeat = TimeSpan.FromMilliseconds(100); await using var runner = TightHeartbeatRunner(heartbeat, TimeSpan.FromSeconds(60), sink); var worker = WarmTight(runner, await runner.RunAsync(Scripts.Vt("warm", Healthy), Ct), heartbeat, sink); + worker.SilenceLimit = TimeSpan.FromMilliseconds(1_500); // see remarks (#1092) string? resumedOn = null; await runner.RunAsync(Scripts.Vt("warm", Healthy), Ct).ContinueWith(t => @@ -565,7 +578,7 @@ public sealed class SupervisionTests // Runs wherever RunAsync's own continuation completed it: the thread that resumed the caller. resumedOn = Thread.CurrentThread.Name; t.Result.Value.ShouldBe(7); - Thread.Sleep(1_500); + Thread.Sleep(3_500); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); // Behaviour first: the worker was not killed for silence while the caller blocked. diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/WorkerSoftClockTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/WorkerSoftClockTests.cs index 926ecbe33..2a7fa4dd8 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/WorkerSoftClockTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/WorkerSoftClockTests.cs @@ -271,9 +271,22 @@ public sealed class WorkerSoftClockTests /// /// Review F1: the soft notice is handled on the pipe READER, and the caller's resumption is the caller's code. It /// must go through the result dispatcher like a result does: a continuation that blocks for 1.5 s must not hold up - /// the reader, or the next heartbeats sit unread and a healthy worker is killed for silence (300 ms here). Before - /// the fix the continuation ran inline on the reader and the worker was killed (KilledHeartbeat). + /// the reader, or the next heartbeats sit unread and a healthy worker is killed for silence (1.5 s here, with a + /// 3.5 s block). Before the fix the continuation ran inline on the reader and the worker was killed (KilledHeartbeat). /// + /// + /// Same limit as SupervisionTests.A_caller_that_blocks_after_its_result_does_not_starve_the_reader: + /// lmxopcua#1092: the limit used to be three 100 ms intervals (300 ms), and this pair of tests failed + /// intermittently on a loaded macOS dev box (about 1 full-suite run in 3–5), the worker killed for "sent nothing + /// for 344 ms" while the reader and the dispatcher worked correctly. Measured with send-stamped heartbeats: the + /// WORKER sent a beat 290–380 ms late (1–150 ms in transit), mid-run, not at startup — a cold worker beat every + /// 100 ± 8 ms from its first beat in 50 isolated runs at load 60–200, with and without 28 CPU burners, and no + /// run outside that real-load full suite (24 of 25.6 GB into swap at the time) stalled at all, whether the + /// heartbeat ran on the thread pool or on a dedicated thread. Those are whole-process stalls of the box, not + /// starvation a worker change can remove. So the limit is 1.5 s (production's is 3 s) and the block 3.5 s: a + /// reader held by the caller still goes silent 2 s past the limit, so the mutation is still killed, and the + /// resumedOn assertion pins the thread outright. + /// [Fact] public async Task A_slow_continuation_of_a_soft_timeout_does_not_stall_the_reader() { @@ -286,7 +299,7 @@ public sealed class WorkerSoftClockTests var entry = await connection.EnsureLoadedAsync("k", ContextKind.VirtualTag, Runaway, SHA256.HashData(Encoding.UTF8.GetBytes(Runaway)), []).WaitAsync(TimeSpan.FromSeconds(60), Ct); entry.Outcome.ShouldNotBeNull().Ok.ShouldBeTrue(); - connection.SilenceLimit = heartbeat * 3; // armed only once the cold start is over (see SupervisionTests) + connection.SilenceLimit = TimeSpan.FromMilliseconds(1_500); // armed once the cold start is over; see remarks (#1092) var softT = TimeSpan.FromMilliseconds(200); var pending = connection.Submit("k", @@ -297,7 +310,7 @@ public sealed class WorkerSoftClockTests { resumedOn = Thread.CurrentThread.Name; t.Result.ShouldBeSameAs(PendingEval.SoftTimedOut); - Thread.Sleep(1_500); + Thread.Sleep(3_500); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); await slowConsumer.WaitAsync(TimeSpan.FromSeconds(10), Ct);