rollbridge 0.1.69 → 0.1.71
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 +1 -53
- package/TODO.md +0 -12
- package/docs/cli.md +3 -128
- package/docs/config.md +6 -177
- package/docs/troubleshooting.md +6 -97
- package/docs/velocious.md +1 -1
- package/docs/workers.md +0 -11
- package/examples/tensorbuzz.com.js +2 -3
- package/package.json +1 -1
- package/src/cli.js +2 -68
- package/src/config.js +8 -347
- package/src/daemon.js +69 -370
- package/src/doctor.js +0 -74
- package/src/guardian-client.js +8 -67
- package/src/health.js +8 -99
- package/src/managed-process.js +16 -197
- package/src/process-guardian.js +21 -211
- package/src/process-memory.js +2 -62
- package/src/release-group.js +37 -427
- package/tensorbuzz.yml +1 -20
- package/test/completion.test.js +2 -5
- package/test/config-validation.test.js +5 -135
- package/test/guardian-client.test.js +4 -118
- package/test/health.test.js +1 -74
- package/test/managed-process.test.js +1 -260
- package/test/owner-recovery.test.js +28 -132
- package/test/owner-replacement.test.js +11 -172
- package/test/process-memory.test.js +1 -47
- package/test/release-group.test.js +2 -408
- package/test/rollbridge.test.js +82 -766
- package/test/shutdown-completion.test.js +0 -52
- package/test/support/process.js +1 -3
- package/changelog.d/20261025-guardian-re-register-dead-generation.md +0 -13
- package/changelog.d/20261026-stale-committed-generation-transition-recovery.md +0 -1
- package/changelog.d/20261104-compose-service-units.md +0 -21
- package/changelog.d/20261105-owner-mutation-lease-diagnostics.md +0 -20
- package/changelog.d/20261106-release-dependency-boot-budgets.md +0 -32
- package/changelog.d/20261109-path-filtered-builds.md +0 -11
- package/changelog.d/20261110-default-boot-budget-above-measured-startup.md +0 -26
- package/changelog.d/20261111-contention-sensitive-daemon-specs.md +0 -27
- package/changelog.d/20261113-bounded-nonblocking-retirement.md +0 -5
- package/changelog.d/20261115-bound-draining-release-groups.md +0 -62
- package/changelog.d/20261115-restore-deploy-refuses-held-generation.md +0 -27
- package/changelog.d/20261115-wedged-generation-escalation.md +0 -44
- package/changelog.d/20261116-bounded-explicit-stop-retirement.md +0 -30
- package/changelog.d/20261116-config-json-canonical-shape.md +0 -11
- package/changelog.d/20261116-drain-specs-gate-the-retirement-record.md +0 -29
- package/changelog.d/20261116-guardian-version-handoff.md +0 -37
- package/changelog.d/20261116-reclaim-dead-owner-mutation.md +0 -7
- package/changelog.d/20261117-activation-path-drain-deadline.md +0 -35
- package/changelog.d/20261117-stop-companion-after-retired-dependency.md +0 -7
- package/docs/compose-services.md +0 -222
- package/src/compose-unit.js +0 -725
- package/src/drain-policy.js +0 -252
- package/src/process-order.js +0 -26
- package/test/compose-config.test.js +0 -160
- package/test/compose-docker.test.js +0 -297
- package/test/compose-unit.test.js +0 -415
- package/test/drain-policy.test.js +0 -328
- package/test/fixtures/deferred-boot-app.js +0 -106
- package/test/fixtures/gated-app.js +0 -50
- package/test/tensorbuzz-config.test.js +0 -228
package/src/managed-process.js
CHANGED
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import {EventEmitter} from "node:events"
|
|
4
4
|
import {spawn} from "node:child_process"
|
|
5
|
-
import {processGroupHasLiveMembers, processGroupMembers
|
|
5
|
+
import {processGroupHasLiveMembers, processGroupMembers} from "./process-memory.js"
|
|
6
6
|
|
|
7
7
|
const DEFAULT_ACTIVATION_HOOK_TIMEOUT_MS = 30000
|
|
8
8
|
const MAX_BUFFERED_OUTPUT_CHARACTERS = 64 * 1024
|
|
9
|
-
// Reading a process group means scanning procfs, and status() is read continuously. A held
|
|
10
|
-
// group is re-verified on this interval instead of on every read.
|
|
11
|
-
const HELD_GROUP_RECHECK_MS = 5000
|
|
12
|
-
// How long an escalated SIGKILL is given to clear the group before the group is recorded as
|
|
13
|
-
// outliving it again. Bounded so the escalation itself can never become the unbounded wait it
|
|
14
|
-
// replaced.
|
|
15
|
-
const ESCALATION_KILL_CONFIRM_MS = 5000
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* @typedef {import("./json.js").JsonValue} JsonValue
|
|
@@ -22,9 +15,8 @@ const ESCALATION_KILL_CONFIRM_MS = 5000
|
|
|
22
15
|
* @typedef {import("node:child_process").ChildProcess["signalCode"]} ProcessExitSignal
|
|
23
16
|
* @typedef {{at: string, line: string, stream: "stdout" | "stderr"}} ManagedProcessLog
|
|
24
17
|
* @typedef {import("./config.js").StopTimeoutMs} StopTimeoutMs
|
|
25
|
-
* @typedef {{command: string, cwd: string | undefined, env: Record<string, string | undefined>, lifecycle: import("./config.js").LifecycleConfig, logger: (message: string, data?: Record<string, import("./json.js").JsonValue>) => void, memory: import("./config.js").MemoryConfig | undefined, outputLines: number, restart: import("./config.js").RestartConfig, restartDelayMs: number, shouldRestart: () => boolean,
|
|
26
|
-
* @typedef {{
|
|
27
|
-
* @typedef {{children: import("./process-memory.js").ProcessGroupMember[], command: string, cwd: string | undefined, exitCode: number | null | undefined, exitSignal: ProcessExitSignal | undefined, heldProcessGroup: HeldProcessGroup | undefined, id: string, lastMemoryRestartAt: string | undefined, lastStartReason: ManagedProcessStartReason | undefined, lifecycleRole?: LifecycleRole, logs: ManagedProcessLog[], memoryRestarts: number, pid: number | undefined, restarts: number, retirementTimedOut: boolean, rssBytes: number | undefined, startedAt: string | undefined, state: ManagedProcessState, uptimeMs: number | undefined}} ManagedProcessStatus
|
|
18
|
+
* @typedef {{command: string, cwd: string | undefined, env: Record<string, string | undefined>, lifecycle: import("./config.js").LifecycleConfig, logger: (message: string, data?: Record<string, import("./json.js").JsonValue>) => void, memory: import("./config.js").MemoryConfig | undefined, outputLines: number, restart: import("./config.js").RestartConfig, restartDelayMs: number, shouldRestart: () => boolean, stopSignal: string, stopTimeoutMs: StopTimeoutMs}} ManagedProcessDefinition
|
|
19
|
+
* @typedef {{children: import("./process-memory.js").ProcessGroupMember[], command: string, cwd: string | undefined, exitCode: number | null | undefined, exitSignal: ProcessExitSignal | undefined, id: string, lastMemoryRestartAt: string | undefined, lastStartReason: ManagedProcessStartReason | undefined, lifecycleRole?: LifecycleRole, logs: ManagedProcessLog[], memoryRestarts: number, pid: number | undefined, restarts: number, rssBytes: number | undefined, startedAt: string | undefined, state: ManagedProcessState, uptimeMs: number | undefined}} ManagedProcessStatus
|
|
28
20
|
*/
|
|
29
21
|
|
|
30
22
|
export default class ManagedProcess extends EventEmitter {
|
|
@@ -41,11 +33,10 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
41
33
|
* @param {import("./config.js").RestartConfig} [args.restart] - Restart policy (defaults to unlimited restarts with a constant delay).
|
|
42
34
|
* @param {number} args.restartDelayMs - Restart delay.
|
|
43
35
|
* @param {() => boolean} args.shouldRestart - Restart policy callback.
|
|
44
|
-
* @param {() => boolean} [args.shouldStop] - Whether an unexpected exit is terminal because its dependency retired.
|
|
45
36
|
* @param {string} [args.stopSignal] - Signal sent to gracefully stop the process (default "SIGTERM").
|
|
46
37
|
* @param {StopTimeoutMs} args.stopTimeoutMs - Stop timeout.
|
|
47
38
|
*/
|
|
48
|
-
constructor({command, cwd, env, id, lifecycle = {drainTimeoutMs: 0}, logger, memory, outputLines, restart = {backoffFactor: 1, maxDelayMs: 0, maxRestarts: undefined, windowMs: 0}, restartDelayMs, shouldRestart,
|
|
39
|
+
constructor({command, cwd, env, id, lifecycle = {drainTimeoutMs: 0}, logger, memory, outputLines, restart = {backoffFactor: 1, maxDelayMs: 0, maxRestarts: undefined, windowMs: 0}, restartDelayMs, shouldRestart, stopSignal = "SIGTERM", stopTimeoutMs}) {
|
|
49
40
|
super()
|
|
50
41
|
|
|
51
42
|
this.command = command
|
|
@@ -59,7 +50,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
59
50
|
this.restart = restart
|
|
60
51
|
this.restartDelayMs = restartDelayMs
|
|
61
52
|
this.shouldRestart = shouldRestart
|
|
62
|
-
this.shouldStop = shouldStop
|
|
63
53
|
this.stopSignal = stopSignal
|
|
64
54
|
this.stopTimeoutMs = stopTimeoutMs
|
|
65
55
|
this.state = /** @type {ManagedProcessState} */ ("stopped")
|
|
@@ -83,10 +73,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
83
73
|
this.quiescePromise = /** @type {Promise<void> | undefined} */ (undefined)
|
|
84
74
|
this.quiesceError = /** @type {Error | undefined} */ (undefined)
|
|
85
75
|
this.stopPromise = /** @type {Promise<void> | undefined} */ (undefined)
|
|
86
|
-
this.retirementTimedOut = false
|
|
87
|
-
this.groupOutlivedStop = /** @type {number | undefined} */ (undefined)
|
|
88
|
-
this.heldProcessGroupCheckedAtMs = /** @type {number | undefined} */ (undefined)
|
|
89
|
-
this.heldProcessGroupCount = /** @type {number | undefined} */ (undefined)
|
|
90
76
|
this.operationRevision = 0
|
|
91
77
|
this.restartTimer = undefined
|
|
92
78
|
this.child = undefined
|
|
@@ -114,10 +100,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
114
100
|
this.quiescePromise = undefined
|
|
115
101
|
this.quiesceError = undefined
|
|
116
102
|
this.stopPromise = undefined
|
|
117
|
-
this.retirementTimedOut = false
|
|
118
|
-
this.groupOutlivedStop = undefined
|
|
119
|
-
this.heldProcessGroupCheckedAtMs = undefined
|
|
120
|
-
this.heldProcessGroupCount = undefined
|
|
121
103
|
this.exitCode = undefined
|
|
122
104
|
this.exitSignal = undefined
|
|
123
105
|
this.state = "starting"
|
|
@@ -209,7 +191,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
209
191
|
this.restart = definition.restart
|
|
210
192
|
this.restartDelayMs = definition.restartDelayMs
|
|
211
193
|
this.shouldRestart = definition.shouldRestart
|
|
212
|
-
this.shouldStop = definition.shouldStop ?? (() => false)
|
|
213
194
|
this.stopSignal = definition.stopSignal
|
|
214
195
|
this.stopTimeoutMs = definition.stopTimeoutMs
|
|
215
196
|
}
|
|
@@ -268,80 +249,15 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
268
249
|
this.rssBytes = undefined
|
|
269
250
|
this.children = []
|
|
270
251
|
this.clearMemoryMonitor()
|
|
271
|
-
|
|
272
|
-
this.state = wasIntentional || terminalExit ? "stopped" : "failed"
|
|
273
|
-
|
|
252
|
+
this.state = wasIntentional ? "stopped" : "failed"
|
|
274
253
|
this.logger("process exited", {code, id: this.id, signal})
|
|
275
254
|
this.emit("exit", {code, signal})
|
|
276
255
|
|
|
277
|
-
if (!wasIntentional &&
|
|
256
|
+
if (!wasIntentional && this.shouldRestart()) {
|
|
278
257
|
this.scheduleRestart()
|
|
279
258
|
}
|
|
280
259
|
}
|
|
281
260
|
|
|
282
|
-
/**
|
|
283
|
-
* Records that the owned process group was still alive when the bounded stop gave up.
|
|
284
|
-
*
|
|
285
|
-
* Every process is spawned `detached: true`, so the tracked pid is the group leader and a
|
|
286
|
-
* member that survives its leader — a `sh` wrapper killed by the stop signal while the app
|
|
287
|
-
* it launched keeps running, or a runner child that outlives its parent — keeps holding the
|
|
288
|
-
* group id while the tracked ChildProcess record is already terminal. Nothing in rollbridge
|
|
289
|
-
* can wait for or signal that group again, yet the group still holds the release's work.
|
|
290
|
-
*
|
|
291
|
-
* Only the stop path can know this, and it already observed the group while waiting for it to
|
|
292
|
-
* leave, so the group id is recorded there instead of rediscovered in `onExit`: that hook
|
|
293
|
-
* fires for every retired process, and a procfs scan costs ~200 ms per exit on a busy host.
|
|
294
|
-
* @param {number} pgid - Process group id the tracked process led.
|
|
295
|
-
* @returns {void}
|
|
296
|
-
*/
|
|
297
|
-
markGroupOutlivedStop(pgid) {
|
|
298
|
-
if (this.groupOutlivedStop === pgid) return
|
|
299
|
-
|
|
300
|
-
this.groupOutlivedStop = pgid
|
|
301
|
-
this.heldProcessGroupCheckedAtMs = undefined
|
|
302
|
-
this.heldProcessGroupCount = undefined
|
|
303
|
-
this.logger("process group outlived its tracked process", {id: this.id, pgid})
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Reports the process group left behind by a bounded stop, as observed right now.
|
|
308
|
-
*
|
|
309
|
-
* The record is re-verified rather than trusted forever: once the orphaned members exit, the
|
|
310
|
-
* group is gone and stops holding the key. Re-verification is rate-limited to
|
|
311
|
-
* `HELD_GROUP_RECHECK_MS` because it costs a procfs scan, and when procfs cannot answer at
|
|
312
|
-
* all the last known state is reported instead of guessing that the group is gone.
|
|
313
|
-
* @returns {HeldProcessGroup | undefined} The held group, or undefined when nothing is held.
|
|
314
|
-
*/
|
|
315
|
-
currentHeldProcessGroup() {
|
|
316
|
-
const pgid = this.groupOutlivedStop
|
|
317
|
-
|
|
318
|
-
if (pgid === undefined) return undefined
|
|
319
|
-
if (this.state !== "stopped" && this.state !== "failed") return undefined
|
|
320
|
-
|
|
321
|
-
const nowMs = Date.now()
|
|
322
|
-
|
|
323
|
-
if (this.heldProcessGroupCount !== undefined && this.heldProcessGroupCheckedAtMs !== undefined && nowMs - this.heldProcessGroupCheckedAtMs < HELD_GROUP_RECHECK_MS) {
|
|
324
|
-
return {liveMemberCount: this.heldProcessGroupCount, pgid}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const sample = sampleProcessGroup(pgid)
|
|
328
|
-
|
|
329
|
-
this.heldProcessGroupCheckedAtMs = nowMs
|
|
330
|
-
|
|
331
|
-
if (sample === undefined) return {liveMemberCount: this.heldProcessGroupCount, pgid}
|
|
332
|
-
|
|
333
|
-
if (sample.memberCount === 0) {
|
|
334
|
-
this.groupOutlivedStop = undefined
|
|
335
|
-
this.heldProcessGroupCount = undefined
|
|
336
|
-
|
|
337
|
-
return undefined
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
this.heldProcessGroupCount = sample.liveMemberCount
|
|
341
|
-
|
|
342
|
-
return {liveMemberCount: sample.liveMemberCount, pgid}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
261
|
/**
|
|
346
262
|
* Schedules an automatic restart per the restart policy, or gives up once the policy's limit is reached.
|
|
347
263
|
* @returns {void}
|
|
@@ -495,8 +411,8 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
495
411
|
}
|
|
496
412
|
|
|
497
413
|
/**
|
|
498
|
-
* @param {{
|
|
499
|
-
* @returns {Promise<void>} Resolves when stopped
|
|
414
|
+
* @param {{timeoutMs?: number}} [options] - Stop options.
|
|
415
|
+
* @returns {Promise<void>} Resolves when stopped.
|
|
500
416
|
*/
|
|
501
417
|
async stop(options = {}) {
|
|
502
418
|
this.operationRevision += 1
|
|
@@ -505,13 +421,12 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
505
421
|
}
|
|
506
422
|
|
|
507
423
|
/**
|
|
508
|
-
* @param {{
|
|
509
|
-
* @returns {Promise<void>} Resolves when stopped
|
|
424
|
+
* @param {{timeoutMs?: number}} options - Stop options.
|
|
425
|
+
* @returns {Promise<void>} Resolves when stopped.
|
|
510
426
|
*/
|
|
511
427
|
async performStop(options) {
|
|
512
428
|
const pgid = this.child?.pid ?? this.pid
|
|
513
429
|
const exitPromise = this.exitPromise
|
|
514
|
-
const retirementDeadline = options.retirementTimeoutMs === undefined ? undefined : Date.now() + options.retirementTimeoutMs
|
|
515
430
|
await this.quiesce()
|
|
516
431
|
|
|
517
432
|
if (!pgid) {
|
|
@@ -533,43 +448,23 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
533
448
|
// 3. Stop whatever is still running, then SIGKILL if it outlasts the graceful window.
|
|
534
449
|
if (this.processGroupExists(pgid)) {
|
|
535
450
|
const timeoutMs = options.timeoutMs ?? this.stopTimeoutMs
|
|
536
|
-
|
|
537
|
-
// A retirement budget is the caller's decision that this process must not be waited for and
|
|
538
|
-
// must not be killed, so it caps the graceful window rather than only standing in for a
|
|
539
|
-
// missing one. Read the other way round, a finite `gracefulStopMs` outvotes the retirement
|
|
540
|
-
// bound and the wait runs for the whole window: TensorBuzz production moved its worker from
|
|
541
|
-
// `"indefinite"` to 4,5 h and the stop would still have held the control plane for 4,5 h.
|
|
542
|
-
const retirementBound = retirementDeadline !== undefined && (gracefulDeadline === undefined || retirementDeadline < gracefulDeadline)
|
|
543
|
-
const waitDeadline = retirementBound ? retirementDeadline : gracefulDeadline
|
|
451
|
+
let gracefulDeadline
|
|
544
452
|
|
|
545
453
|
if (stopCommand) {
|
|
546
454
|
await this.runHook(stopCommand, hookTimeoutMs, "stop command", pgid)
|
|
455
|
+
gracefulDeadline = timeoutMs === "indefinite" ? undefined : Date.now() + timeoutMs
|
|
547
456
|
} else {
|
|
548
457
|
this.intentionalStopSignal = /** @type {ProcessExitSignal} */ (this.stopSignal)
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
const exited = await this.waitForProcessGroupExit(pgid, waitDeadline)
|
|
553
|
-
|
|
554
|
-
if (!exited && retirementBound) {
|
|
555
|
-
this.retirementTimedOut = true
|
|
556
|
-
this.markGroupOutlivedStop(pgid)
|
|
557
|
-
// The tracked process has completed its supervised stop even though its process group is
|
|
558
|
-
// still draining. Keep the residue in heldProcessGroup rather than leaving the process
|
|
559
|
-
// permanently quiesced, which would make a drained generation look active to restore
|
|
560
|
-
// admission and keep the owner state from describing the actual stopped generation.
|
|
561
|
-
this.state = "stopped"
|
|
562
|
-
this.logger("process retirement wait timed out; leaving process alive", {id: this.id, pid: pgid, timeoutMs: options.retirementTimeoutMs})
|
|
563
|
-
return
|
|
458
|
+
gracefulDeadline = timeoutMs === "indefinite" ? undefined : Date.now() + timeoutMs
|
|
459
|
+
await this.signalProcessGroup(this.stopSignal, pgid, gracefulDeadline)
|
|
564
460
|
}
|
|
565
461
|
|
|
566
|
-
if (!
|
|
462
|
+
if (!(await this.waitForProcessGroupExit(pgid, gracefulDeadline))) {
|
|
567
463
|
this.logger("process stop timed out; sending SIGKILL", {id: this.id, pid: pgid})
|
|
568
464
|
const killDeadline = Date.now() + 5000
|
|
569
465
|
|
|
570
466
|
await this.signalProcessGroup("SIGKILL", pgid, killDeadline)
|
|
571
|
-
|
|
572
|
-
if (!await this.waitForProcessGroupExit(pgid, killDeadline)) this.markGroupOutlivedStop(pgid)
|
|
467
|
+
await this.waitForProcessGroupExit(pgid, killDeadline)
|
|
573
468
|
}
|
|
574
469
|
}
|
|
575
470
|
|
|
@@ -578,49 +473,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
578
473
|
this.state = "stopped"
|
|
579
474
|
}
|
|
580
475
|
|
|
581
|
-
/**
|
|
582
|
-
* Delivers the SIGKILL that retirement proved it must not wait for.
|
|
583
|
-
*
|
|
584
|
-
* Retirement deliberately leaves a non-blocking process alive: STOE-1077 measured what a
|
|
585
|
-
* stop-timeout kill costs when the process still holds live lanes (67 builds, 27.3
|
|
586
|
-
* build-hours). That is right while the process can still drain and wrong once it cannot — a
|
|
587
|
-
* wedged generation keeps its release open, keeps its port reservation, and makes every
|
|
588
|
-
* later deploy wait on it until an operator signals the exact PIDs by hand. This is the
|
|
589
|
-
* acting half of that decision, and it re-checks the two invariants this class owns before
|
|
590
|
-
* sending anything: the process must already be recorded as past its retirement budget, and
|
|
591
|
-
* its group must still have a member that can be signalled.
|
|
592
|
-
* @param {{reason: string}} options - Named evidence behind the escalation.
|
|
593
|
-
* @returns {Promise<boolean>} True when a live process group was signalled.
|
|
594
|
-
*/
|
|
595
|
-
async escalateRetirement({reason}) {
|
|
596
|
-
const pgid = this.pid ?? this.groupOutlivedStop
|
|
597
|
-
|
|
598
|
-
if (pgid === undefined) return false
|
|
599
|
-
|
|
600
|
-
if (!this.retirementTimedOut) {
|
|
601
|
-
this.logger("retirement escalation refused; process is not past its retirement budget", {id: this.id, pid: pgid})
|
|
602
|
-
|
|
603
|
-
return false
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
if (!this.processGroupExists(pgid)) {
|
|
607
|
-
this.groupOutlivedStop = undefined
|
|
608
|
-
this.heldProcessGroupCount = undefined
|
|
609
|
-
|
|
610
|
-
return false
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
this.logger("process retirement escalated to SIGKILL", {id: this.id, pid: pgid, reason})
|
|
614
|
-
|
|
615
|
-
const killDeadline = Date.now() + ESCALATION_KILL_CONFIRM_MS
|
|
616
|
-
|
|
617
|
-
await this.signalProcessGroup("SIGKILL", pgid, killDeadline)
|
|
618
|
-
|
|
619
|
-
if (!await this.waitForProcessGroupExit(pgid, killDeadline)) this.markGroupOutlivedStop(pgid)
|
|
620
|
-
|
|
621
|
-
return true
|
|
622
|
-
}
|
|
623
|
-
|
|
624
476
|
/** @returns {Promise<void>} Stops restarts and waits until the process has stopped accepting new work. */
|
|
625
477
|
async quiesce() {
|
|
626
478
|
if (this.quiescePromise) return await this.quiescePromise
|
|
@@ -763,19 +615,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
763
615
|
return this.stopTimeoutMs
|
|
764
616
|
}
|
|
765
617
|
|
|
766
|
-
/**
|
|
767
|
-
* Reports whether this process's graceful window has no upper bound.
|
|
768
|
-
*
|
|
769
|
-
* `"indefinite"` is the consumer's statement that the supervisor must never kill this process;
|
|
770
|
-
* it is not a statement that a caller may wait for it forever. A stop that has no retirement
|
|
771
|
-
* budget for such a process can only hang, and when that stop runs inside an owner mutation it
|
|
772
|
-
* locks out every later mutation (STOE-2015).
|
|
773
|
-
* @returns {boolean} True when no deadline can ever end the wait.
|
|
774
|
-
*/
|
|
775
|
-
hasUnboundedGracefulWindow() {
|
|
776
|
-
return this.stopTimeoutMs === "indefinite"
|
|
777
|
-
}
|
|
778
|
-
|
|
779
618
|
/**
|
|
780
619
|
* Runs a lifecycle hook command, bounded by a timeout so a hung hook can never block stop().
|
|
781
620
|
* Failures are logged and returned so generation retirement can surface a failed quiet hook;
|
|
@@ -978,7 +817,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
978
817
|
cwd: this.cwd,
|
|
979
818
|
exitCode: this.exitCode,
|
|
980
819
|
exitSignal: this.exitSignal,
|
|
981
|
-
heldProcessGroup: this.currentHeldProcessGroup(),
|
|
982
820
|
id: this.id,
|
|
983
821
|
lastMemoryRestartAt: this.lastMemoryRestartAtMs === undefined ? undefined : new Date(this.lastMemoryRestartAtMs).toISOString(),
|
|
984
822
|
lastStartReason: this.lastStartReason,
|
|
@@ -987,7 +825,6 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
987
825
|
memoryRestarts: this.memoryRestarts,
|
|
988
826
|
pid: this.pid,
|
|
989
827
|
restarts: this.restarts,
|
|
990
|
-
retirementTimedOut: this.retirementTimedOut,
|
|
991
828
|
rssBytes: this.rssBytes,
|
|
992
829
|
startedAt: this.startedAtMs === undefined ? undefined : new Date(this.startedAtMs).toISOString(),
|
|
993
830
|
state: this.state,
|
|
@@ -995,21 +832,3 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
995
832
|
}
|
|
996
833
|
}
|
|
997
834
|
}
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* The guardian's provenance fence, in one place: a registered child stops fencing a later
|
|
1001
|
-
* claim on its key only when its record is terminal *and* it holds no pid, and a process
|
|
1002
|
-
* group that outlived the tracked process is not gone either.
|
|
1003
|
-
*
|
|
1004
|
-
* Both the guardian (re-registering a key under a new provenance) and the daemon (restoring a
|
|
1005
|
-
* release that is recorded as drained) must agree on this, or a restore reaches the guardian
|
|
1006
|
-
* and fails there with a bare `Guardian provenance mismatch` naming a process the operator
|
|
1007
|
-
* cannot see in `status`.
|
|
1008
|
-
* @param {Pick<ManagedProcessStatus, "heldProcessGroup" | "pid" | "state">} status - Process status record.
|
|
1009
|
-
* @returns {boolean} True when the child is conclusively gone.
|
|
1010
|
-
*/
|
|
1011
|
-
export function childRecordIsGone(status) {
|
|
1012
|
-
if (status.heldProcessGroup) return false
|
|
1013
|
-
|
|
1014
|
-
return (status.state === "stopped" || status.state === "failed") && status.pid === undefined
|
|
1015
|
-
}
|