@smoothbricks/nx-plugin 0.7.18 → 0.7.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -99
- package/dist/.build-inputs.json +35 -29
- package/dist/built-output-packages.js +1 -1
- package/dist/cargo-closure-input.js +1 -1
- package/dist/cargo-source-hash.d.ts +3 -21
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +4 -91
- package/dist/cargo-toolchain-paths.d.ts +2 -2
- package/dist/cargo-toolchain-paths.js +2 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +2 -1
- package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
- package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
- package/dist/executors/bounded-exec/admission-queue.js +9 -10
- package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
- package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
- package/dist/executors/bounded-exec/awake-clock.js +22 -0
- package/dist/executors/bounded-exec/bounds.d.ts +7 -5
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +14 -11
- package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
- package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
- package/dist/executors/bounded-exec/case-gate.js +342 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
- package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +102 -16
- package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
- package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
- package/dist/executors/bounded-exec/endpoint-life.js +228 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +207 -69
- package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +8 -1
- package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
- package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
- package/dist/executors/bounded-exec/go-run-summary.js +98 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +3 -3
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +66 -48
- package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
- package/dist/executors/bounded-exec/lease-wait.js +1 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +28 -7
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +30 -9
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +8 -5
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +187 -283
- package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
- package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
- package/dist/executors/bounded-exec/parent-grant.js +1 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
- package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
- package/dist/executors/bounded-exec/pool-admission.js +47 -1
- package/dist/executors/bounded-exec/progress.d.ts +3 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +31 -1
- package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
- package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
- package/dist/executors/bounded-exec/reservation-connection.js +248 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
- package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +13 -9
- package/dist/executors/bounded-exec/schema.d.ts +2 -2
- package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
- package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
- package/dist/executors/bounded-exec/suite-minimum.js +85 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-result-writer.js +1 -0
- package/dist/executors/bounded-exec/test-results.d.ts +5 -0
- package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-results.js +2 -2
- package/dist/executors/bounded-exec/verdict.d.ts +26 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +26 -5
- package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
- package/dist/executors/cargo-zigbuild/executor.js +32 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -73
- package/dist/managed-files/ci-workflow.d.ts +4 -1
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +9 -14
- package/dist/managed-files/files.d.ts +3 -3
- package/dist/managed-files/files.js +3 -3
- package/dist/task-results.js +2 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +135 -42
- package/executors.json +2 -0
- package/managed/raw/envrc +24 -0
- package/managed/raw/patches/nx@24.0.3.patch +1179 -133
- package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
- package/managed/raw/tooling/direnv/developer-links.ts +105 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
- package/package.json +67 -11
- package/runtime/nx-publish/.build-inputs.json +2 -2
- package/runtime/nx-publish/cache_adapter.js +293 -3
- package/runtime/nx-publish/nx_publish.js +36 -14
- package/src/built-output-packages.ts +1 -1
- package/src/cargo-closure-input.ts +1 -1
- package/src/cargo-source-hash.ts +16 -132
- package/src/cargo-toolchain-paths.ts +2 -2
- package/src/cargo-workspace.ts +1 -2
- package/src/executors/bounded-exec/admission-queue.ts +11 -10
- package/src/executors/bounded-exec/awake-clock.ts +20 -0
- package/src/executors/bounded-exec/bounds.ts +28 -15
- package/src/executors/bounded-exec/case-gate.ts +365 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
- package/src/executors/bounded-exec/cpu-pool.ts +139 -12
- package/src/executors/bounded-exec/endpoint-life.ts +279 -0
- package/src/executors/bounded-exec/executor.ts +280 -106
- package/src/executors/bounded-exec/gateway-lease.ts +6 -0
- package/src/executors/bounded-exec/go-run-summary.ts +137 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +70 -52
- package/src/executors/bounded-exec/lease-wait.ts +1 -0
- package/src/executors/bounded-exec/mbx-pool.ts +36 -9
- package/src/executors/bounded-exec/mbx-reservations.ts +213 -182
- package/src/executors/bounded-exec/parent-grant.ts +3 -0
- package/src/executors/bounded-exec/pool-admission.ts +59 -2
- package/src/executors/bounded-exec/progress.ts +37 -2
- package/src/executors/bounded-exec/reservation-connection.ts +221 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
- package/src/executors/bounded-exec/runner-sizing.ts +13 -8
- package/src/executors/bounded-exec/schema.json +1 -1
- package/src/executors/bounded-exec/schema.ts +2 -2
- package/src/executors/bounded-exec/suite-minimum.ts +81 -0
- package/src/executors/bounded-exec/test-result-writer.ts +3 -0
- package/src/executors/bounded-exec/test-results.ts +5 -0
- package/src/executors/bounded-exec/verdict.ts +39 -6
- package/src/executors/cargo-zigbuild/executor.ts +30 -19
- package/src/index.ts +112 -78
- package/src/managed-files/ci-workflow.ts +13 -17
- package/src/managed-files/files.ts +3 -3
- package/src/workspace-config-policy.ts +161 -43
- package/test-timings.json +157 -147
- package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
|
@@ -16,12 +16,24 @@ import { ownedSocketDirectory } from '../../testing.js';
|
|
|
16
16
|
import { holdLease } from './gateway-lease.js';
|
|
17
17
|
import { readLiveUsage } from './host-memory.js';
|
|
18
18
|
import { CpuLeaseWait, HEARTBEAT_MS } from './lease-wait.js';
|
|
19
|
-
import { admit } from './pool-admission.js';
|
|
19
|
+
import { admit, IdleBesideStarved, place } from './pool-admission.js';
|
|
20
20
|
import { poolEnvironment } from './pool-environment.js';
|
|
21
|
+
/**
|
|
22
|
+
* The settle time (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself"): Nx starts a run's next
|
|
23
|
+
* task when one ends, and that task's leaf takes what its predecessor freed before any case is lent it.
|
|
24
|
+
*/
|
|
25
|
+
const LEND_SETTLE_MS = 3_000;
|
|
26
|
+
const LENDING = { settleMs: LEND_SETTLE_MS, now: () => performance.now() };
|
|
27
|
+
/** The line a run's pool says of `summary` when it closes; null for a pool that starved no leaf and lent nothing. */
|
|
28
|
+
export function describeIdle(summary) {
|
|
29
|
+
return summary.starved === 0 && summary.lent === 0
|
|
30
|
+
? null
|
|
31
|
+
: `cowshed: cpu-pool idle beside_starved_core_s=${(summary.idleBesideStarvedMs / 1000).toFixed(3)} starved=${summary.starved} lent=${summary.lent}\n`;
|
|
32
|
+
}
|
|
21
33
|
/** Exactly a request's fields: any other field is an invalid request. */
|
|
22
34
|
const isRequest = (() => {
|
|
23
|
-
const _io0 = (input, _exceptionable = true) => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (undefined === input.memory || "number" === typeof input.memory && _isTypeUint64_1._isTypeUint64(input.memory)) && (undefined === input.parallelism || "number" === typeof input.parallelism && (_isTypeUint32_1._isTypeUint32(input.parallelism) && 1 <= input.parallelism)) && (undefined === input.task || "string" === typeof input.task && _stringLengthLte_1._stringLengthLte(input.task, 256)) && (undefined === input.alone || "boolean" === typeof input.alone) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
24
|
-
if (["op", "want", "memory", "parallelism", "task", "alone"].some(prop => key === prop))
|
|
35
|
+
const _io0 = (input, _exceptionable = true) => "cpu-pool" === input.op && ("number" === typeof input.want && (_isTypeUint32_1._isTypeUint32(input.want) && 1 <= input.want)) && (undefined === input.memory || "number" === typeof input.memory && _isTypeUint64_1._isTypeUint64(input.memory)) && (undefined === input.parallelism || "number" === typeof input.parallelism && (_isTypeUint32_1._isTypeUint32(input.parallelism) && 1 <= input.parallelism)) && (undefined === input.task || "string" === typeof input.task && _stringLengthLte_1._stringLengthLte(input.task, 256)) && (undefined === input.alone || "boolean" === typeof input.alone) && (undefined === input.lend || "boolean" === typeof input.lend) && (undefined === input.left || "number" === typeof input.left && _isTypeUint64_1._isTypeUint64(input.left)) && (undefined === input.gated || "boolean" === typeof input.gated) && (2 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
36
|
+
if (["op", "want", "memory", "parallelism", "task", "alone", "lend", "left", "gated"].some(prop => key === prop))
|
|
25
37
|
return true;
|
|
26
38
|
const value = input[key];
|
|
27
39
|
if (undefined === value)
|
|
@@ -97,7 +109,7 @@ const isOversized = (() => {
|
|
|
97
109
|
* the child beside its parent's count.
|
|
98
110
|
*/
|
|
99
111
|
export async function takeParentCpuTokens(parent, want, memory, context = {}) {
|
|
100
|
-
const { parallelism, task, alone } = context;
|
|
112
|
+
const { parallelism, task, alone, gated } = context;
|
|
101
113
|
if (!Number.isSafeInteger(want) || want < 1) {
|
|
102
114
|
throw new RangeError(`a child asks its parent pool for a positive count, not ${want} (pool ${parent.tokens})`);
|
|
103
115
|
}
|
|
@@ -120,6 +132,7 @@ export async function takeParentCpuTokens(parent, want, memory, context = {}) {
|
|
|
120
132
|
...(memory === null ? {} : { memory, ...(parallelism === undefined ? {} : { parallelism }) }),
|
|
121
133
|
...(task === undefined ? {} : { task }),
|
|
122
134
|
...(alone === true ? { alone: true } : {}),
|
|
135
|
+
...(gated === true ? { gated: true } : {}),
|
|
123
136
|
};
|
|
124
137
|
const lease = await holdLease(parent.socket, request, 'the parent CPU pool', new CpuLeaseWait());
|
|
125
138
|
if (!lease.granted) {
|
|
@@ -159,6 +172,32 @@ export async function takeParentCpuTokens(parent, want, memory, context = {}) {
|
|
|
159
172
|
closed: lease.closed,
|
|
160
173
|
};
|
|
161
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* One token of `parent` asked for one test case of a leaf that holds a grant of it, named `task` in the request
|
|
177
|
+
* (specs/cowshed/05_gateway.md, "A case starts on a core", Inside a hold). The pool grants it only while no other
|
|
178
|
+
* request waits. `release` gives the token back, or withdraws the request while it waits. A pool that refuses, falls
|
|
179
|
+
* silent or is gone grants nothing: the case waits for a token of its leaf's own grant.
|
|
180
|
+
*/
|
|
181
|
+
export function lendParentToken(parent, task, left) {
|
|
182
|
+
const withdrawn = new AbortController();
|
|
183
|
+
const lease = holdLease(parent.socket, { op: 'cpu-pool', want: 1, lend: true, left: Math.max(0, Math.round(left)), task: task.slice(0, MAX_TASK_LENGTH) }, 'the parent CPU pool', new CpuLeaseWait(), undefined, withdrawn.signal);
|
|
184
|
+
let released = false;
|
|
185
|
+
return {
|
|
186
|
+
granted: lease.then((held) => held.granted && !released),
|
|
187
|
+
release: () => {
|
|
188
|
+
if (released)
|
|
189
|
+
return;
|
|
190
|
+
released = true;
|
|
191
|
+
withdrawn.abort();
|
|
192
|
+
void lease.then((held) => {
|
|
193
|
+
if (held.granted)
|
|
194
|
+
held.release();
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** A request's `task` is at most this long (`CpuPoolRequest`). */
|
|
200
|
+
const MAX_TASK_LENGTH = 256;
|
|
162
201
|
/** A thrown value's message. */
|
|
163
202
|
const describe = (error) => (error instanceof Error ? error.message : String(error));
|
|
164
203
|
/** Write `count` token bytes to the fifo's descriptor; a short write throws. The fifo holds a pipe buffer of them. */
|
|
@@ -297,7 +336,7 @@ function watchFifo(path, took, failed) {
|
|
|
297
336
|
* (`liveUsage`); a sub-pool charges none (null).
|
|
298
337
|
* Setup failures are values; a non-positive or unsafe count is a programmer bug and throws.
|
|
299
338
|
*/
|
|
300
|
-
export async function createCpuPool(tokens, closed, memory, liveUsage = readLiveUsage) {
|
|
339
|
+
export async function createCpuPool(tokens, closed, memory, liveUsage = readLiveUsage, lending = LENDING) {
|
|
301
340
|
if (!Number.isSafeInteger(tokens) || tokens < 1) {
|
|
302
341
|
throw new RangeError(`a CPU pool holds a positive safe integer of tokens, not ${tokens}`);
|
|
303
342
|
}
|
|
@@ -330,6 +369,15 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
330
369
|
// The children holding a grant, and whether one of them runs alone.
|
|
331
370
|
let holders = 0;
|
|
332
371
|
let aloneHolder = false;
|
|
372
|
+
// The tokens socket grants hold, the leaves that hold fewer than they asked and take no gate, and what the pool says
|
|
373
|
+
// of both when it closes.
|
|
374
|
+
let heldTokens = 0;
|
|
375
|
+
let starvedHolders = 0;
|
|
376
|
+
let partialGrants = 0;
|
|
377
|
+
let lentGrants = 0;
|
|
378
|
+
const idle = new IdleBesideStarved(lending.now());
|
|
379
|
+
// A leaf return arms this one-shot window. A later leaf return replaces it; a case return does not.
|
|
380
|
+
let settle;
|
|
333
381
|
// The readability wait while the queue's head finds no token, else undefined.
|
|
334
382
|
let watch;
|
|
335
383
|
let closing = false;
|
|
@@ -410,7 +458,7 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
410
458
|
return;
|
|
411
459
|
}
|
|
412
460
|
}
|
|
413
|
-
const admission = admit(queue, inHand + (slotLent ? 0 : 1), memory === null ? null : { capacity: memory.bytes, held: heldMemory }, { holders, alone: aloneHolder });
|
|
461
|
+
const admission = admit(queue, inHand + (slotLent ? 0 : 1), memory === null ? null : { capacity: memory.bytes, held: heldMemory }, { holders, alone: aloneHolder }, settle === undefined);
|
|
414
462
|
queue.splice(0, admission.grants.length);
|
|
415
463
|
for (const { request, tokens: granted, charge, oversized } of admission.grants) {
|
|
416
464
|
// Fifo bytes first, the implicit slot last.
|
|
@@ -421,15 +469,33 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
421
469
|
slotLent = true;
|
|
422
470
|
heldMemory += charge;
|
|
423
471
|
holders += 1;
|
|
472
|
+
heldTokens += granted;
|
|
473
|
+
const partial = granted < request.want;
|
|
474
|
+
const starved = partial && request.gated !== true;
|
|
475
|
+
if (partial)
|
|
476
|
+
partialGrants += 1;
|
|
477
|
+
if (starved)
|
|
478
|
+
starvedHolders += 1;
|
|
479
|
+
if (request.lend === true)
|
|
480
|
+
lentGrants += 1;
|
|
424
481
|
if (request.alone === true)
|
|
425
482
|
aloneHolder = true;
|
|
426
|
-
request.child.phase = {
|
|
483
|
+
request.child.phase = {
|
|
484
|
+
kind: 'holding',
|
|
485
|
+
bytes,
|
|
486
|
+
slot,
|
|
487
|
+
memory: charge,
|
|
488
|
+
alone: request.alone === true,
|
|
489
|
+
tokens: granted,
|
|
490
|
+
starved,
|
|
491
|
+
lend: request.lend === true,
|
|
492
|
+
};
|
|
427
493
|
request.child.socket.write(frame(memory === null
|
|
428
494
|
? { ok: true, lease: 'granted', tokens: granted }
|
|
429
495
|
: oversized
|
|
430
496
|
? { ok: true, lease: 'granted', tokens: granted, charged: charge, oversized: { memory: memory.bytes } }
|
|
431
497
|
: { ok: true, lease: 'granted', tokens: granted, charged: charge }));
|
|
432
|
-
if (memory !== null) {
|
|
498
|
+
if (memory !== null && request.lend !== true) {
|
|
433
499
|
const live = liveUsage(memory.source);
|
|
434
500
|
const held = live.ok
|
|
435
501
|
? `${live.usage.anon + live.usage.shmem} bytes (anon ${live.usage.anon}, shmem ${live.usage.shmem}, ${live.usage.source})`
|
|
@@ -444,6 +510,7 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
444
510
|
stopWatching();
|
|
445
511
|
}
|
|
446
512
|
returnTokens(inHand);
|
|
513
|
+
idle.observe(lending.now(), tokens - heldTokens, starvedHolders > 0 || queue.at(-1)?.lend === true);
|
|
447
514
|
}
|
|
448
515
|
const refuse = (child, error) => {
|
|
449
516
|
child.phase = { kind: 'done' };
|
|
@@ -473,6 +540,18 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
473
540
|
slotLent = false;
|
|
474
541
|
heldMemory -= child.phase.memory;
|
|
475
542
|
holders -= 1;
|
|
543
|
+
heldTokens -= child.phase.tokens;
|
|
544
|
+
if (child.phase.starved)
|
|
545
|
+
starvedHolders -= 1;
|
|
546
|
+
// What a leaf returns is its successor's first: Nx starts the run's next task as this one ends.
|
|
547
|
+
if (!closing && !child.phase.lend && lending.settleMs > 0) {
|
|
548
|
+
clearTimeout(settle);
|
|
549
|
+
settle = setTimeout(() => {
|
|
550
|
+
settle = undefined;
|
|
551
|
+
drain(0);
|
|
552
|
+
}, lending.settleMs);
|
|
553
|
+
settle.unref();
|
|
554
|
+
}
|
|
476
555
|
if (child.phase.alone)
|
|
477
556
|
aloneHolder = false;
|
|
478
557
|
if (!closing)
|
|
@@ -534,6 +613,10 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
534
613
|
refuse(child, 'a request is {"op":"cpu-pool","want":<a whole number of tokens, at least 1>,"memory"?:<bytes it is charged>}');
|
|
535
614
|
return;
|
|
536
615
|
}
|
|
616
|
+
if (parsed.lend === true && (parsed.want !== 1 || parsed.memory !== undefined || parsed.alone === true)) {
|
|
617
|
+
refuse(child, 'a lent request is one token for one test case: {"op":"cpu-pool","want":1,"lend":true,"task"?:<its case>}');
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
537
620
|
const request = parsed;
|
|
538
621
|
child.phase = { kind: 'queued' };
|
|
539
622
|
const waiter = {
|
|
@@ -543,15 +626,11 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
543
626
|
parallelism: request.parallelism,
|
|
544
627
|
task: request.task,
|
|
545
628
|
alone: request.alone,
|
|
629
|
+
lend: request.lend,
|
|
630
|
+
left: request.left,
|
|
631
|
+
gated: request.gated,
|
|
546
632
|
};
|
|
547
|
-
|
|
548
|
-
// A leaf the kernel killed has waited once already: it goes ahead of the leaves that have not run.
|
|
549
|
-
const at = queue.findIndex((waiting) => waiting.alone !== true);
|
|
550
|
-
queue.splice(at === -1 ? queue.length : at, 0, waiter);
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
queue.push(waiter);
|
|
554
|
-
}
|
|
633
|
+
queue.splice(place(queue, waiter), 0, waiter);
|
|
555
634
|
socket.write(frame({ ok: true, lease: 'queued', server: process.pid }));
|
|
556
635
|
drain(0);
|
|
557
636
|
});
|
|
@@ -563,6 +642,8 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
563
642
|
shut ??= (async () => {
|
|
564
643
|
closing = true;
|
|
565
644
|
clearInterval(heartbeat);
|
|
645
|
+
clearTimeout(settle);
|
|
646
|
+
idle.observe(lending.now(), 0, false);
|
|
566
647
|
stopWatching();
|
|
567
648
|
await started;
|
|
568
649
|
for (const socket of children) {
|
|
@@ -659,5 +740,10 @@ export async function createCpuPool(tokens, closed, memory, liveUsage = readLive
|
|
|
659
740
|
environment: poolEnvironment(socketPath, tokens, fifoPath),
|
|
660
741
|
close: shutdown,
|
|
661
742
|
},
|
|
743
|
+
summary: () => ({
|
|
744
|
+
idleBesideStarvedMs: idle.tokenMs(lending.now()),
|
|
745
|
+
starved: partialGrants,
|
|
746
|
+
lent: lentGrants,
|
|
747
|
+
}),
|
|
662
748
|
};
|
|
663
749
|
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The life of an Nx run's mbx reservation endpoint in the run that started it (mbx-reservations.ts;
|
|
3
|
+
* specs/cowshed/05_gateway.md, "Parallelism inside a job"), as a state machine over what the run can observe of its
|
|
4
|
+
* child. Pure: no I/O, no clock and no timer. The shell maps the child's and the probe's events into `EndpointEvent`s
|
|
5
|
+
* and executes the `EndpointEffect`s each step answers, in their order; it decides nothing.
|
|
6
|
+
*
|
|
7
|
+
* The run waits in four phases, each for events only:
|
|
8
|
+
*
|
|
9
|
+
* - `starting`, for the child's first line on its standard output, or its end. `listening` opens the probe; any other
|
|
10
|
+
* line is refused and the child killed. A child whose standard output ends without a line can say none: its start
|
|
11
|
+
* is refused, by how it ended when it ends within the reap bound, and it is killed when it does not.
|
|
12
|
+
* - `probing`, for the endpoint's answer to `{"type":"capabilities"}` on the probe's connection, or that connection's
|
|
13
|
+
* end: whether the installed mbx's shim gates test cases (05_gateway.md, "A case starts on a core"). The start is
|
|
14
|
+
* then answered served, which publishes the socket to the run's tasks. A child that ends first is refused by how it
|
|
15
|
+
* ended: no task is told of an endpoint that is gone.
|
|
16
|
+
* - `serving`, for the run's end. A child that ends first is `gone`, and the run's end says how.
|
|
17
|
+
* - `ending`, for the child's end once a pipe of it closed (its standard input by the run, its standard output by
|
|
18
|
+
* itself) or it was killed, with the reap timer armed.
|
|
19
|
+
*
|
|
20
|
+
* The start is answered once (`serve` or `refuse`) and a served endpoint's end once (`conclude`); `ended` takes no
|
|
21
|
+
* event.
|
|
22
|
+
*/
|
|
23
|
+
export type EndpointLife = {
|
|
24
|
+
readonly phase: 'starting';
|
|
25
|
+
readonly out: string;
|
|
26
|
+
readonly said: string;
|
|
27
|
+
readonly pid: number | undefined;
|
|
28
|
+
} | {
|
|
29
|
+
readonly phase: 'probing';
|
|
30
|
+
readonly reply: string;
|
|
31
|
+
readonly said: string;
|
|
32
|
+
readonly pid: number | undefined;
|
|
33
|
+
} | {
|
|
34
|
+
readonly phase: 'serving';
|
|
35
|
+
readonly said: string;
|
|
36
|
+
readonly pid: number | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly phase: 'gone';
|
|
39
|
+
readonly ended: Ended;
|
|
40
|
+
} | {
|
|
41
|
+
readonly phase: 'ending';
|
|
42
|
+
readonly pid: number | undefined;
|
|
43
|
+
readonly said: string;
|
|
44
|
+
/** Whether the child was sent SIGKILL; otherwise a pipe of it closed and its end is awaited. */
|
|
45
|
+
readonly killed: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Why its start is refused; null for a served endpoint ending with its run. An unkilled child that ends is
|
|
48
|
+
* refused by how it ended instead, which says more.
|
|
49
|
+
*/
|
|
50
|
+
readonly refusing: string | null;
|
|
51
|
+
} | {
|
|
52
|
+
readonly phase: 'ended';
|
|
53
|
+
};
|
|
54
|
+
/** How a served endpoint ended, and whether that was its ordinary end: status 0 with nothing said, unkilled. */
|
|
55
|
+
export interface Ended {
|
|
56
|
+
readonly how: string;
|
|
57
|
+
readonly clean: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** What the shell observes. `run-end` is the run's own: its `postTasksExecution`, or a held run's question answered. */
|
|
60
|
+
export type EndpointEvent = {
|
|
61
|
+
readonly type: 'stdout';
|
|
62
|
+
readonly text: string;
|
|
63
|
+
} | {
|
|
64
|
+
readonly type: 'stdout-end';
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: 'stderr';
|
|
67
|
+
readonly text: string;
|
|
68
|
+
}
|
|
69
|
+
/** Node's `error` of the child: it could not be spawned. */
|
|
70
|
+
| {
|
|
71
|
+
readonly type: 'error';
|
|
72
|
+
readonly message: string;
|
|
73
|
+
}
|
|
74
|
+
/** Node's `close` of the child: it has exited and its pipes have ended. */
|
|
75
|
+
| {
|
|
76
|
+
readonly type: 'close';
|
|
77
|
+
readonly code: number | null;
|
|
78
|
+
readonly signal: string | null;
|
|
79
|
+
} | {
|
|
80
|
+
readonly type: 'probe';
|
|
81
|
+
readonly text: string;
|
|
82
|
+
}
|
|
83
|
+
/** The probe's connection ended or failed. */
|
|
84
|
+
| {
|
|
85
|
+
readonly type: 'probe-end';
|
|
86
|
+
} | {
|
|
87
|
+
readonly type: 'run-end';
|
|
88
|
+
}
|
|
89
|
+
/** The reap timer the last `arm` started has run out. */
|
|
90
|
+
| {
|
|
91
|
+
readonly type: 'expired';
|
|
92
|
+
};
|
|
93
|
+
/** What the shell does. `refuse` and `conclude` remove the socket's directory before they answer. */
|
|
94
|
+
export type EndpointEffect =
|
|
95
|
+
/** Connect to the endpoint's socket and send it `{"type":"capabilities"}`. */
|
|
96
|
+
{
|
|
97
|
+
readonly do: 'probe';
|
|
98
|
+
}
|
|
99
|
+
/** End the probe's connection. */
|
|
100
|
+
| {
|
|
101
|
+
readonly do: 'hang-up';
|
|
102
|
+
}
|
|
103
|
+
/** Answer the start: the endpoint serves, and its mbx gates test cases or does not. */
|
|
104
|
+
| {
|
|
105
|
+
readonly do: 'serve';
|
|
106
|
+
readonly gates: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** Answer the start: no endpoint, and why. */
|
|
109
|
+
| {
|
|
110
|
+
readonly do: 'refuse';
|
|
111
|
+
readonly why: string;
|
|
112
|
+
} | {
|
|
113
|
+
readonly do: 'close-stdin';
|
|
114
|
+
} | {
|
|
115
|
+
readonly do: 'kill';
|
|
116
|
+
}
|
|
117
|
+
/** Stop the child and its pipes from keeping the run alive, without signalling it again. */
|
|
118
|
+
| {
|
|
119
|
+
readonly do: 'unref-child';
|
|
120
|
+
} | {
|
|
121
|
+
readonly do: 'arm';
|
|
122
|
+
readonly ms: number;
|
|
123
|
+
} | {
|
|
124
|
+
readonly do: 'disarm';
|
|
125
|
+
}
|
|
126
|
+
/** Answer the run's end. */
|
|
127
|
+
| {
|
|
128
|
+
readonly do: 'conclude';
|
|
129
|
+
readonly ended: Ended;
|
|
130
|
+
};
|
|
131
|
+
export type EndpointStep = readonly [EndpointLife, readonly EndpointEffect[]];
|
|
132
|
+
/** The life of a child just spawned; `pid` is what names it should it not end when killed. */
|
|
133
|
+
export declare function spawned(pid: number | undefined): EndpointLife;
|
|
134
|
+
/**
|
|
135
|
+
* Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
|
|
136
|
+
* request answers an error, which gates nothing.
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
|
|
140
|
+
* request answers an error, which gates nothing, and so does a line that is no JSON: typia's parse validates what
|
|
141
|
+
* `JSON.parse` returns and throws what it throws.
|
|
142
|
+
*/
|
|
143
|
+
export declare function gatesTests(line: string): boolean;
|
|
144
|
+
/** The next state of `life` at `event`, and what the shell does about it. */
|
|
145
|
+
export declare function endpointStep(life: EndpointLife, event: EndpointEvent): EndpointStep;
|
|
146
|
+
//# sourceMappingURL=endpoint-life.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-life.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/endpoint-life.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC7G;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC9G;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACtF;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAA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AIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOhD;AA+BD,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAenF"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import * as _validateReport_1 from "typia/lib/internal/_validateReport";
|
|
2
|
+
import typia from 'typia';
|
|
3
|
+
import { REAP_MS } from './lease-wait.js';
|
|
4
|
+
/** What is kept of the endpoint's stderr to say why it ended: its last bytes. */
|
|
5
|
+
const SAID_BYTES = 4096;
|
|
6
|
+
/** The life of a child just spawned; `pid` is what names it should it not end when killed. */
|
|
7
|
+
export function spawned(pid) {
|
|
8
|
+
return { phase: 'starting', out: '', said: '', pid };
|
|
9
|
+
}
|
|
10
|
+
const ENDED = { phase: 'ended' };
|
|
11
|
+
const parseCapabilities = (() => {
|
|
12
|
+
let errors;
|
|
13
|
+
let _report;
|
|
14
|
+
const _io0 = input => "capabilities" === input.type && "boolean" === typeof input.test_gate;
|
|
15
|
+
const _vo0 = (input, _path, _exceptionable = true) => ["capabilities" === input.type || _report(_exceptionable, {
|
|
16
|
+
path: _path + ".type",
|
|
17
|
+
expected: "\"capabilities\"",
|
|
18
|
+
value: input.type
|
|
19
|
+
}), "boolean" === typeof input.test_gate || _report(_exceptionable, {
|
|
20
|
+
path: _path + ".test_gate",
|
|
21
|
+
expected: "boolean",
|
|
22
|
+
value: input.test_gate
|
|
23
|
+
})].every(flag => flag);
|
|
24
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
25
|
+
const __validate = input => {
|
|
26
|
+
if (false === __is(input)) {
|
|
27
|
+
errors = [];
|
|
28
|
+
_report = _validateReport_1._validateReport(errors);
|
|
29
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
30
|
+
path: _path + "",
|
|
31
|
+
expected: "CapabilitiesReply",
|
|
32
|
+
value: input
|
|
33
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
34
|
+
path: _path + "",
|
|
35
|
+
expected: "CapabilitiesReply",
|
|
36
|
+
value: input
|
|
37
|
+
}))(input, "$input", true);
|
|
38
|
+
const success = 0 === errors.length;
|
|
39
|
+
return success ? {
|
|
40
|
+
success,
|
|
41
|
+
data: input
|
|
42
|
+
} : {
|
|
43
|
+
success,
|
|
44
|
+
errors,
|
|
45
|
+
data: input
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
success: true,
|
|
50
|
+
data: input
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
return input => __validate(JSON.parse(input));
|
|
54
|
+
})();
|
|
55
|
+
/**
|
|
56
|
+
* Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
|
|
57
|
+
* request answers an error, which gates nothing.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Whether the mbx that answered `line` to `{"type":"capabilities"}` gates test cases. One that does not know the
|
|
61
|
+
* request answers an error, which gates nothing, and so does a line that is no JSON: typia's parse validates what
|
|
62
|
+
* `JSON.parse` returns and throws what it throws.
|
|
63
|
+
*/
|
|
64
|
+
export function gatesTests(line) {
|
|
65
|
+
try {
|
|
66
|
+
const reply = parseCapabilities(line);
|
|
67
|
+
return reply.success && reply.data.test_gate;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** `text` up to its first line break, or null while it holds none. */
|
|
74
|
+
function firstLine(text) {
|
|
75
|
+
const end = text.indexOf('\n');
|
|
76
|
+
return end === -1 ? null : text.slice(0, end);
|
|
77
|
+
}
|
|
78
|
+
function saying(said, text) {
|
|
79
|
+
return (said + text).slice(-SAID_BYTES);
|
|
80
|
+
}
|
|
81
|
+
function closed(said, code, signal) {
|
|
82
|
+
const last = said.trim().split('\n').at(-1) ?? '';
|
|
83
|
+
return {
|
|
84
|
+
how: `mbx reservations ended ${signal === null ? `with status ${code}` : `on ${signal}`}${last === '' ? '' : `: ${last}`}`,
|
|
85
|
+
clean: signal === null && code === 0 && last === '',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function unspawned(message) {
|
|
89
|
+
return { how: `mbx reservations could not run: ${message}`, clean: false };
|
|
90
|
+
}
|
|
91
|
+
/** How the child ended, when `event` is its end. */
|
|
92
|
+
function endOf(said, event) {
|
|
93
|
+
if (event.type === 'close')
|
|
94
|
+
return closed(said, event.code, event.signal);
|
|
95
|
+
if (event.type === 'error')
|
|
96
|
+
return unspawned(event.message);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
/** The next state of `life` at `event`, and what the shell does about it. */
|
|
100
|
+
export function endpointStep(life, event) {
|
|
101
|
+
switch (life.phase) {
|
|
102
|
+
case 'starting':
|
|
103
|
+
return starting(life, event);
|
|
104
|
+
case 'probing':
|
|
105
|
+
return probing(life, event);
|
|
106
|
+
case 'serving':
|
|
107
|
+
return serving(life, event);
|
|
108
|
+
case 'gone':
|
|
109
|
+
return event.type === 'run-end' ? [ENDED, [{ do: 'conclude', ended: life.ended }]] : [life, []];
|
|
110
|
+
case 'ending':
|
|
111
|
+
return ending(life, event);
|
|
112
|
+
case 'ended':
|
|
113
|
+
return [life, []];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function unanswered(phase) {
|
|
117
|
+
throw new Error(`the run's end reached its endpoint while ${phase}: the run holds no endpoint before its start is answered`);
|
|
118
|
+
}
|
|
119
|
+
function starting(life, event) {
|
|
120
|
+
const ended = endOf(life.said, event);
|
|
121
|
+
if (ended !== null)
|
|
122
|
+
return [ENDED, [{ do: 'refuse', why: ended.how }]];
|
|
123
|
+
switch (event.type) {
|
|
124
|
+
case 'stderr':
|
|
125
|
+
return [{ ...life, said: saying(life.said, event.text) }, []];
|
|
126
|
+
case 'stdout': {
|
|
127
|
+
const out = life.out + event.text;
|
|
128
|
+
const line = firstLine(out);
|
|
129
|
+
if (line === null)
|
|
130
|
+
return [{ ...life, out }, []];
|
|
131
|
+
if (line === 'listening') {
|
|
132
|
+
return [{ phase: 'probing', reply: '', said: life.said, pid: life.pid }, [{ do: 'probe' }]];
|
|
133
|
+
}
|
|
134
|
+
return [
|
|
135
|
+
{
|
|
136
|
+
phase: 'ending',
|
|
137
|
+
pid: life.pid,
|
|
138
|
+
said: life.said,
|
|
139
|
+
killed: true,
|
|
140
|
+
refusing: `mbx reservations said ${JSON.stringify(line)}, not that it was listening`,
|
|
141
|
+
},
|
|
142
|
+
[{ do: 'kill' }, { do: 'arm', ms: REAP_MS }],
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
case 'stdout-end': {
|
|
146
|
+
const unsaid = `mbx reservations closed its standard output ${life.out === '' ? '' : `after ${JSON.stringify(life.out)}, `}without saying it was listening`;
|
|
147
|
+
return [
|
|
148
|
+
{ phase: 'ending', pid: life.pid, said: life.said, killed: false, refusing: unsaid },
|
|
149
|
+
[{ do: 'arm', ms: REAP_MS }],
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
case 'run-end':
|
|
153
|
+
return unanswered(life.phase);
|
|
154
|
+
default:
|
|
155
|
+
return [life, []];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function probing(life, event) {
|
|
159
|
+
const served = { phase: 'serving', said: life.said, pid: life.pid };
|
|
160
|
+
const ended = endOf(life.said, event);
|
|
161
|
+
if (ended !== null)
|
|
162
|
+
return [ENDED, [{ do: 'hang-up' }, { do: 'refuse', why: ended.how }]];
|
|
163
|
+
switch (event.type) {
|
|
164
|
+
case 'stderr':
|
|
165
|
+
return [{ ...life, said: saying(life.said, event.text) }, []];
|
|
166
|
+
case 'probe': {
|
|
167
|
+
const reply = life.reply + event.text;
|
|
168
|
+
const line = firstLine(reply);
|
|
169
|
+
if (line === null)
|
|
170
|
+
return [{ ...life, reply }, []];
|
|
171
|
+
return [served, [{ do: 'hang-up' }, { do: 'serve', gates: gatesTests(line) }]];
|
|
172
|
+
}
|
|
173
|
+
case 'probe-end':
|
|
174
|
+
return [served, [{ do: 'serve', gates: false }]];
|
|
175
|
+
case 'run-end':
|
|
176
|
+
return unanswered(life.phase);
|
|
177
|
+
default:
|
|
178
|
+
return [life, []];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function serving(life, event) {
|
|
182
|
+
const ended = endOf(life.said, event);
|
|
183
|
+
if (ended !== null)
|
|
184
|
+
return [{ phase: 'gone', ended }, []];
|
|
185
|
+
switch (event.type) {
|
|
186
|
+
case 'stderr':
|
|
187
|
+
return [{ ...life, said: saying(life.said, event.text) }, []];
|
|
188
|
+
case 'run-end':
|
|
189
|
+
return [
|
|
190
|
+
{ phase: 'ending', said: life.said, pid: life.pid, killed: false, refusing: null },
|
|
191
|
+
[{ do: 'close-stdin' }, { do: 'arm', ms: REAP_MS }],
|
|
192
|
+
];
|
|
193
|
+
default:
|
|
194
|
+
return [life, []];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function ending(life, event) {
|
|
198
|
+
const ended = endOf(life.said, event);
|
|
199
|
+
if (ended !== null) {
|
|
200
|
+
if (life.refusing !== null) {
|
|
201
|
+
return [ENDED, [{ do: 'disarm' }, { do: 'refuse', why: life.killed ? life.refusing : ended.how }]];
|
|
202
|
+
}
|
|
203
|
+
const outlived = life.killed
|
|
204
|
+
? { how: `${ended.how}, killed after it outlived its standard input by ${REAP_MS}ms`, clean: false }
|
|
205
|
+
: ended;
|
|
206
|
+
return [ENDED, [{ do: 'disarm' }, { do: 'conclude', ended: outlived }]];
|
|
207
|
+
}
|
|
208
|
+
switch (event.type) {
|
|
209
|
+
case 'stderr':
|
|
210
|
+
return [{ ...life, said: saying(life.said, event.text) }, []];
|
|
211
|
+
case 'expired': {
|
|
212
|
+
// A closed pipe did not end it within the reap bound: kill it, and wait that bound once more.
|
|
213
|
+
if (!life.killed) {
|
|
214
|
+
const refusing = life.refusing === null ? null : `${life.refusing}, and had not ended ${REAP_MS}ms later`;
|
|
215
|
+
return [{ ...life, killed: true, refusing }, [{ do: 'kill' }, { do: 'arm', ms: REAP_MS }]];
|
|
216
|
+
}
|
|
217
|
+
// Neither did the kill: it is stuck in the kernel, or something it started holds its pipes. The wait ends and
|
|
218
|
+
// says so; the child is left as it is (05_gateway.md, "A child's exit and its output are reap-class waits").
|
|
219
|
+
const left = `${life.pid === undefined ? 'it' : `pid ${life.pid}`} had not ended ${REAP_MS}ms after it was killed and is left as it is`;
|
|
220
|
+
if (life.refusing !== null)
|
|
221
|
+
return [ENDED, [{ do: 'unref-child' }, { do: 'refuse', why: `${life.refusing}; ${left}` }]];
|
|
222
|
+
const how = `mbx reservations outlived its standard input by ${REAP_MS}ms; ${left}`;
|
|
223
|
+
return [ENDED, [{ do: 'unref-child' }, { do: 'conclude', ended: { how, clean: false } }]];
|
|
224
|
+
}
|
|
225
|
+
default:
|
|
226
|
+
return [life, []];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AAeA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/executor.ts"],"names":[],"mappings":"AAeA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAkB5E,OAAO,EAAE,sBAAsB,EAAmB,MAAM,uBAAuB,CAAC;AAchF,OAAO,EAAqB,KAAK,UAAU,EAA8B,MAAM,mBAAmB,CAAC;AAEnG,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAgB,KAAK,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAGlG,OAAO,EASL,aAAa,EAEd,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,KA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