rollbridge 0.1.76 → 0.1.77
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/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -2944,8 +2944,9 @@ export default class RollbridgeDaemon {
|
|
|
2944
2944
|
*/
|
|
2945
2945
|
async drainAndPrune(release, config = this.config) {
|
|
2946
2946
|
try {
|
|
2947
|
-
await release.drainAndStop(config.proxy.drainTimeoutMs, config)
|
|
2948
|
-
this.logger("release drained", {releaseId: release.releaseId})
|
|
2947
|
+
const drained = await release.drainAndStop(config.proxy.drainTimeoutMs, config)
|
|
2948
|
+
if (drained) this.logger("release drained", {releaseId: release.releaseId})
|
|
2949
|
+
else this.logger("release drain remains active", {releaseId: release.releaseId})
|
|
2949
2950
|
} catch (error) {
|
|
2950
2951
|
this.logger("release drain failed", {error: error instanceof Error ? error.message : String(error), releaseId: release.releaseId})
|
|
2951
2952
|
} finally {
|
package/src/managed-process.js
CHANGED
|
@@ -552,9 +552,13 @@ export default class ManagedProcess extends EventEmitter {
|
|
|
552
552
|
|
|
553
553
|
// 2. Drain: let in-flight work finish, bounded by drainTimeoutMs (0 skips the step). A
|
|
554
554
|
// drainCommand blocks until drained; otherwise wait for the process to exit on its own.
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
555
|
+
const drainBudgetMs = retirementDeadline === undefined
|
|
556
|
+
? drainTimeoutMs
|
|
557
|
+
: Math.max(0, Math.min(drainTimeoutMs, retirementDeadline - Date.now()))
|
|
558
|
+
|
|
559
|
+
if (this.processGroupExists(pgid) && drainBudgetMs > 0) {
|
|
560
|
+
if (drainCommand) await this.runHook(drainCommand, drainBudgetMs, "drain command")
|
|
561
|
+
else await this.waitForExit(drainBudgetMs)
|
|
558
562
|
}
|
|
559
563
|
|
|
560
564
|
// 3. Stop whatever is still running, then SIGKILL if it outlasts the graceful window.
|
package/src/release-group.js
CHANGED
|
@@ -886,10 +886,10 @@ export default class ReleaseGroup extends EventEmitter {
|
|
|
886
886
|
* Starts draining and stops once existing connections close or timeout.
|
|
887
887
|
* @param {number} timeoutMs - Drain timeout.
|
|
888
888
|
* @param {import("./config.js").RollbridgeConfig} [config] - Refreshed config governing retirement.
|
|
889
|
-
* @returns {Promise<
|
|
889
|
+
* @returns {Promise<boolean | undefined>} True when every supervised process retired; false when a live process remains; undefined when owner handoff paused the drain.
|
|
890
890
|
*/
|
|
891
891
|
async drainAndStop(timeoutMs, config = this.config) {
|
|
892
|
-
if (this.state === "stopped") return
|
|
892
|
+
if (this.state === "stopped") return this.processesAreRetired()
|
|
893
893
|
|
|
894
894
|
if (this.state !== "draining") await this.beginRetirement(config)
|
|
895
895
|
|
|
@@ -957,6 +957,12 @@ export default class ReleaseGroup extends EventEmitter {
|
|
|
957
957
|
// it does not end silently with the process still holding the release.
|
|
958
958
|
if (retirementBaselineSample) await this.escalateWedgedGeneration({previousSample: retirementBaselineSample, reason: "release retirement"})
|
|
959
959
|
|
|
960
|
+
// A bounded retirement may return while a non-blocking process is still draining, but that
|
|
961
|
+
// is not a completed release drain. Keep the generation in the retirement path so a later
|
|
962
|
+
// deployment can observe or escalate it; a live process must never disappear behind a
|
|
963
|
+
// "release drained" record.
|
|
964
|
+
if (!this.processesAreRetired()) return false
|
|
965
|
+
|
|
960
966
|
this.state = "stopped"
|
|
961
967
|
this.stoppedAt = new Date().toISOString()
|
|
962
968
|
this.releasePortReservations()
|
|
@@ -964,6 +970,16 @@ export default class ReleaseGroup extends EventEmitter {
|
|
|
964
970
|
// The bracket pair is deliberately kept: a generation that stopped with a live process
|
|
965
971
|
// group stays observable, and the deploy path needs the older observation to prove the
|
|
966
972
|
// residue is still flat rather than starting a fresh window from zero.
|
|
973
|
+
return true
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/** @returns {boolean} Whether every supervised process has exited and left no process group behind. */
|
|
977
|
+
processesAreRetired() {
|
|
978
|
+
return [...this.processes.values()].every((processInstance) => {
|
|
979
|
+
const {heldProcessGroup, pid, state} = processInstance.status()
|
|
980
|
+
|
|
981
|
+
return heldProcessGroup === undefined && pid === undefined && (state === "stopped" || state === "failed")
|
|
982
|
+
})
|
|
967
983
|
}
|
|
968
984
|
|
|
969
985
|
/**
|
|
@@ -743,11 +743,12 @@ test("guardian recovery becomes ready before replaying a gated generation hook",
|
|
|
743
743
|
process.kill(recoveredDaemonPid, "SIGTERM")
|
|
744
744
|
await fs.writeFile(retirementGatePath, "release retirement\n")
|
|
745
745
|
await waitForProcessExit(recoveredDaemonPid, 5000)
|
|
746
|
-
|
|
747
|
-
//
|
|
748
|
-
|
|
749
|
-
//
|
|
750
|
-
|
|
746
|
+
// An owner-recovery SIGTERM deliberately leaves the durable guardian alive so it can
|
|
747
|
+
// re-establish ownership and preserve the active generation for the replacement daemon.
|
|
748
|
+
expect(isProcessRunning(guardianPid)).toBe(true)
|
|
749
|
+
// The old generation is quiesced only after traffic switched to the candidate. The candidate
|
|
750
|
+
// remains active under the replacement owner, so its quiet hook must not run during recovery.
|
|
751
|
+
await waitForLifecycleEvents(fixture.lifecycleLogPath, ["activate:v1", "activate:v2", "retire:v1"])
|
|
751
752
|
} finally {
|
|
752
753
|
await fs.writeFile(retirementGatePath, "release retirement\n").catch(() => undefined)
|
|
753
754
|
await sendControlCommand({command: {command: "shutdown"}, path: fixture.socketPath}).catch(() => undefined)
|
|
@@ -200,9 +200,10 @@ test("a wedged non-blocking process cannot block release retirement", async () =
|
|
|
200
200
|
stop: async () => { handoffStopped = true }
|
|
201
201
|
})))
|
|
202
202
|
|
|
203
|
-
await release.drainAndStop(0, {...release.config, proxy: {...release.config.proxy, nonBlockingDrainTimeoutMs: 20}})
|
|
203
|
+
const drained = await release.drainAndStop(0, {...release.config, proxy: {...release.config.proxy, nonBlockingDrainTimeoutMs: 20}})
|
|
204
204
|
|
|
205
|
-
expect(
|
|
205
|
+
expect(drained).toBe(false)
|
|
206
|
+
expect(release.state).toBe("draining")
|
|
206
207
|
expect(handoffStopped).toBe(true)
|
|
207
208
|
expect(logs).toMatchObject([{message: "release non-blocking process still draining", data: {pid: 4242, processId: "worker"}}])
|
|
208
209
|
})
|
|
@@ -534,14 +535,16 @@ test("the retirement transition brackets its own wait and reports a residue it c
|
|
|
534
535
|
stop: async () => {}
|
|
535
536
|
})))
|
|
536
537
|
|
|
537
|
-
await release.drainAndStop(0, {
|
|
538
|
+
const drained = await release.drainAndStop(0, {
|
|
538
539
|
...release.config,
|
|
539
540
|
proxy: {...release.config.proxy, nonBlockingDrainTimeoutMs: 20},
|
|
540
541
|
releaseRetention: {...release.config.releaseRetention, escalateWedgedGenerations: true}
|
|
541
542
|
})
|
|
542
543
|
|
|
543
|
-
// The transition
|
|
544
|
-
|
|
544
|
+
// The transition keeps the live process supervised: the escalation is its last act, never a
|
|
545
|
+
// wait of its own, and no false "release drained" claim can be emitted.
|
|
546
|
+
expect(drained).toBe(false)
|
|
547
|
+
expect(release.state).toBe("draining")
|
|
545
548
|
expect(escalations).toEqual([])
|
|
546
549
|
expect(release.drainPriorSample).toBeDefined()
|
|
547
550
|
expect(release.drainNewestSample).toBeDefined()
|
package/test/rollbridge.test.js
CHANGED
|
@@ -2298,11 +2298,11 @@ test("rollback refuses to restore a drained generation that still holds live pro
|
|
|
2298
2298
|
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
2299
2299
|
await daemon.deploy({releaseId: "v2", releasePath: fixture.root, revision: "v2"})
|
|
2300
2300
|
|
|
2301
|
-
// The retirement budget expires, Rollbridge
|
|
2301
|
+
// The retirement budget expires, Rollbridge keeps the generation in the drain path, and the
|
|
2302
2302
|
// worker stays alive with its in-flight work — the shape a restore must not re-deploy.
|
|
2303
2303
|
// The tracked process (the shell wrapper) is already gone, so the only honest record of
|
|
2304
2304
|
// the leak is the process group that outlived it.
|
|
2305
|
-
await waitFor(() => statusRelease(daemon, "v1").state === "
|
|
2305
|
+
await waitFor(() => statusRelease(daemon, "v1").state === "draining")
|
|
2306
2306
|
await retirementRecordSettled(daemon, "v1", "worker")
|
|
2307
2307
|
|
|
2308
2308
|
const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
|
|
@@ -2314,7 +2314,7 @@ test("rollback refuses to restore a drained generation that still holds live pro
|
|
|
2314
2314
|
expect(worker.pid).toBeUndefined()
|
|
2315
2315
|
expect(worker.retirementTimedOut).toBe(true)
|
|
2316
2316
|
expect(worker.state).toBe("stopped")
|
|
2317
|
-
await expect(daemon.rollback({releaseId: "v1"})).rejects.toThrow(/
|
|
2317
|
+
await expect(daemon.rollback({releaseId: "v1"})).rejects.toThrow(/Deploy refused before activation: release "v1" is retained in state stopped while 1 process of that generation still hold live work \(worker: process group \d+ with \d+ live member\(s\) still alive after the tracked process exited\)\. Activating that release id again would re-register those processes under a new provenance and abort with a guardian provenance mismatch\. The guardian's active release is "v2"/)
|
|
2318
2318
|
expect(daemon.status().activeReleaseId).toBe("v2")
|
|
2319
2319
|
expect(await fetchText(daemon, "/release")).toBe("v2")
|
|
2320
2320
|
} finally {
|
|
@@ -2375,10 +2375,10 @@ test("a restore deploy naming a drained generation that outlived its tracked pro
|
|
|
2375
2375
|
await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
|
|
2376
2376
|
await daemon.deploy({releaseId: "v2", releasePath: fixture.root, revision: "v2"})
|
|
2377
2377
|
|
|
2378
|
-
// v1
|
|
2378
|
+
// v1 remains in the drain path while its worker keeps its in-flight work in the group its
|
|
2379
2379
|
// shell wrapper led. The 2026-10-25 carve-out that lets a dead generation's process key be
|
|
2380
2380
|
// re-registered does not apply here: the group is alive, so the key is still held.
|
|
2381
|
-
await waitFor(() => statusRelease(daemon, "v1").state === "
|
|
2381
|
+
await waitFor(() => statusRelease(daemon, "v1").state === "draining")
|
|
2382
2382
|
await retirementRecordSettled(daemon, "v1", "worker")
|
|
2383
2383
|
|
|
2384
2384
|
const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
|
|
@@ -2387,7 +2387,7 @@ test("a restore deploy naming a drained generation that outlived its tracked pro
|
|
|
2387
2387
|
throw new Error(`the drained generation should still hold the worker's process group, got ${JSON.stringify(worker && {pid: worker.pid, retirementTimedOut: worker.retirementTimedOut, state: worker.state})}`)
|
|
2388
2388
|
}
|
|
2389
2389
|
|
|
2390
|
-
await expect(daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})).rejects.toThrow(/Deploy refused before activation: release "v1" is retained in state
|
|
2390
|
+
await expect(daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})).rejects.toThrow(/Deploy refused before activation: release "v1" is retained in state draining while 1 process of that generation still hold live work \(worker: process group \d+ with \d+ live member\(s\) still alive after the tracked process exited\)\. Activating that release id again would re-register those processes under a new provenance and abort with a guardian provenance mismatch\. The guardian's active release is "v2"/)
|
|
2391
2391
|
expect(daemon.status().activeReleaseId).toBe("v2")
|
|
2392
2392
|
expect(daemon.status().releases.filter((release) => release.releaseId === "v1").length).toBe(1)
|
|
2393
2393
|
expect(await fetchText(daemon, "/release")).toBe("v2")
|