fix(scripting): #1064 the ScriptWorker applies the in-process result rule — a returned lazy sequence is materialised inside the run and held to Scripting:MaxResultElements (Hello.max_result_elements), same value and same failure text in both runners
This commit is contained in:
@@ -764,7 +764,8 @@ public sealed class OutOfProcessScriptRunner : IPhysicalScriptRunner, IAsyncDisp
|
||||
LoadTimeout: LoadTimeout,
|
||||
CompileThreads: _compileThreads,
|
||||
WorkerSid: WorkerSid,
|
||||
HeartbeatSilenceLimit: _heartbeatSilenceLimit);
|
||||
HeartbeatSilenceLimit: _heartbeatSilenceLimit,
|
||||
MaxResultElements: _options.MaxResultElements);
|
||||
return new WorkerShard(label, isolation,
|
||||
(onExiting, ct) => WorkerConnection.StartAsync(spec, _log, OnLogs, onExiting, ct),
|
||||
OnWorkerExit, _log);
|
||||
|
||||
@@ -102,6 +102,11 @@ internal sealed record BatchSubmission(string Key, EvalRequest Request, TimeSpan
|
||||
/// Ask the worker to run the soft clock from each run's start (lmxopcua#827; see <see cref="WorkerConnection.WorkerSoftClock"/>).
|
||||
/// False (tests only) keeps the pre-#827 host clock, which is also what a worker that does not echo it gets.
|
||||
/// </param>
|
||||
/// <param name="MaxResultElements">
|
||||
/// <c>Scripting:MaxResultElements</c> (lmxopcua#1064): the element cap the worker holds a value script's returned
|
||||
/// sequence to while materialising it inside the run — the same rule the in-process guard applies (#1059). 0 = the
|
||||
/// worker's default.
|
||||
/// </param>
|
||||
internal sealed record WorkerLaunchSpec(
|
||||
string Shard,
|
||||
string WorkerPath,
|
||||
@@ -117,7 +122,8 @@ internal sealed record WorkerLaunchSpec(
|
||||
string? WorkerSid = null,
|
||||
bool WorkerSoftClock = true,
|
||||
TimeSpan? HeartbeatSilenceLimit = null,
|
||||
bool TestStallReaderOnDiag = false)
|
||||
bool TestStallReaderOnDiag = false,
|
||||
int MaxResultElements = 0)
|
||||
{
|
||||
/// <summary>The default compile timeout.</summary>
|
||||
public static readonly TimeSpan DefaultLoadTimeout = TimeSpan.FromSeconds(60);
|
||||
@@ -448,6 +454,7 @@ internal sealed class WorkerConnection : IAsyncDisposable
|
||||
CompileThreads = (uint)Math.Max(0, spec.CompileThreads),
|
||||
WorkerSoftClock = spec.WorkerSoftClock,
|
||||
TestStallReaderOnDiag = spec.TestStallReaderOnDiag,
|
||||
MaxResultElements = (uint)Math.Max(0, spec.MaxResultElements),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -53,6 +53,11 @@ message Hello {
|
||||
// Test seam (lmxopcua#789): the worker's reader stops reading for good at the first DiagnosticsRequest while its
|
||||
// heartbeats go on, so the host's write-stall check can be exercised against a real worker. Never set in production.
|
||||
bool test_stall_reader_on_diag = 12;
|
||||
// lmxopcua#1064: Scripting:MaxResultElements. A value script's returned sequence is materialised inside the run and
|
||||
// held to this element cap, exactly as the in-process ScriptRunGuard does (ScriptResultMaterializer, #1059) — so a
|
||||
// lazy sequence is enumerated in the worker's run (under its deadlines), and an over-cap result fails the script the
|
||||
// same way in both runners. 0 = the worker's default (ScriptingOptions.DefaultMaxResultElements).
|
||||
uint32 max_result_elements = 13;
|
||||
}
|
||||
|
||||
message Ready {
|
||||
|
||||
@@ -39,8 +39,14 @@ public sealed class ScriptResultException : InvalidOperationException
|
||||
/// non-terminating loop are still only contained by the guard's after-the-fact allocation sample and its timeout
|
||||
/// (an orphaned thread). Only <c>Scripting:Runner=OutOfProcess</c> contains those. See docs/VirtualTags.md.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The ONE result rule for both runners (lmxopcua#1064): the in-process <see cref="ScriptRunGuard"/> and the
|
||||
/// out-of-process <c>ScriptWorker</c> both call <see cref="Materialize"/> right after a value script returns,
|
||||
/// inside the run, with the node's <c>Scripting:MaxResultElements</c> (the worker receives it in its
|
||||
/// <c>Hello</c>). Public for that reason only.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal static class ScriptResultMaterializer
|
||||
public static class ScriptResultMaterializer
|
||||
{
|
||||
/// <summary>Materialises <paramref name="value"/> as described on the type.</summary>
|
||||
/// <param name="value">The script's returned value.</param>
|
||||
|
||||
Reference in New Issue
Block a user