@jeffusion/bungee 6.16.2 → 6.17.0
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/dist/index.js +80 -44
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -19902,32 +19902,58 @@ async function bounded2(work) {
|
|
|
19902
19902
|
clearTimeout(timer);
|
|
19903
19903
|
});
|
|
19904
19904
|
}
|
|
19905
|
-
async function readProcessTreeSnapshot(pid) {
|
|
19905
|
+
async function readProcessTreeSnapshot(pid, options = {}) {
|
|
19906
19906
|
const root = `/proc/${pid}`;
|
|
19907
|
-
const
|
|
19908
|
-
|
|
19909
|
-
|
|
19910
|
-
|
|
19911
|
-
|
|
19912
|
-
|
|
19913
|
-
|
|
19914
|
-
if (parsed.state === "Z")
|
|
19915
|
-
throw new TargetProcessMissingError(`process ${pid} is a zombie`);
|
|
19916
|
-
const cmdline = command.toString().split("\x00").filter(Boolean);
|
|
19917
|
-
const env = await bounded2(readFile2(`${root}/environ`));
|
|
19918
|
-
const roleEntry = env.toString().split("\x00").find((value) => value.startsWith("BUNGEE_ROLE="));
|
|
19919
|
-
return {
|
|
19920
|
-
pid,
|
|
19921
|
-
ppid: parsed.ppid,
|
|
19922
|
-
startTime: parsed.startTime,
|
|
19923
|
-
state: parsed.state,
|
|
19924
|
-
uid: uidFromStatus(status),
|
|
19925
|
-
executable: normalizedExecutable(executable),
|
|
19926
|
-
cmdline,
|
|
19927
|
-
bootNonce: bootFromArgv(cmdline),
|
|
19928
|
-
processIdentity: processIdentityFromArgv(cmdline),
|
|
19929
|
-
role: roleEntry?.slice("BUNGEE_ROLE=".length) ?? null
|
|
19907
|
+
const read = options.readFile ?? readFile2;
|
|
19908
|
+
const terminal = async () => {
|
|
19909
|
+
if (options.expected === undefined)
|
|
19910
|
+
return false;
|
|
19911
|
+
const stat = statParts(await bounded2(read(`${root}/stat`, "utf8")));
|
|
19912
|
+
const uid = uidFromStatus(await bounded2(read(`${root}/status`, "utf8")));
|
|
19913
|
+
return stat.state === "Z" && stat.startTime === options.expected.startTime && uid === options.expected.uid;
|
|
19930
19914
|
};
|
|
19915
|
+
try {
|
|
19916
|
+
const [statText, command, status, executable] = await bounded2(Promise.all([
|
|
19917
|
+
read(`${root}/stat`, "utf8"),
|
|
19918
|
+
read(`${root}/cmdline`),
|
|
19919
|
+
read(`${root}/status`, "utf8"),
|
|
19920
|
+
(options.realpath ?? realpath3)(`${root}/exe`)
|
|
19921
|
+
]));
|
|
19922
|
+
const parsed = statParts(statText);
|
|
19923
|
+
if (parsed.state === "Z")
|
|
19924
|
+
throw new Error(`process ${pid} terminal identity is unavailable`);
|
|
19925
|
+
const cmdline = command.toString().split("\x00").filter(Boolean);
|
|
19926
|
+
const env = await bounded2(read(`${root}/environ`));
|
|
19927
|
+
const roleEntry = env.toString().split("\x00").find((value) => value.startsWith("BUNGEE_ROLE="));
|
|
19928
|
+
return {
|
|
19929
|
+
pid,
|
|
19930
|
+
ppid: parsed.ppid,
|
|
19931
|
+
startTime: parsed.startTime,
|
|
19932
|
+
state: parsed.state,
|
|
19933
|
+
uid: uidFromStatus(status),
|
|
19934
|
+
executable: normalizedExecutable(executable),
|
|
19935
|
+
cmdline,
|
|
19936
|
+
bootNonce: bootFromArgv(cmdline),
|
|
19937
|
+
processIdentity: processIdentityFromArgv(cmdline),
|
|
19938
|
+
role: roleEntry?.slice("BUNGEE_ROLE=".length) ?? null
|
|
19939
|
+
};
|
|
19940
|
+
} catch (error) {
|
|
19941
|
+
if (error instanceof TargetProcessMissingError)
|
|
19942
|
+
throw error;
|
|
19943
|
+
const alive = await (options.liveness ?? (async (target) => {
|
|
19944
|
+
try {
|
|
19945
|
+
process.kill(target, 0);
|
|
19946
|
+
return "alive";
|
|
19947
|
+
} catch (probeError) {
|
|
19948
|
+
return probeError.code === "ESRCH" ? "dead" : "unknown";
|
|
19949
|
+
}
|
|
19950
|
+
}))(pid).catch(() => "unknown");
|
|
19951
|
+
if (alive === "dead")
|
|
19952
|
+
throw new TargetProcessMissingError(`target process ${pid} is missing`);
|
|
19953
|
+
if (await terminal().catch(() => false))
|
|
19954
|
+
throw new TargetProcessMissingError(`process ${pid} is a zombie`);
|
|
19955
|
+
throw error;
|
|
19956
|
+
}
|
|
19931
19957
|
}
|
|
19932
19958
|
async function captureProcessTree(rootPid) {
|
|
19933
19959
|
const entries = await bounded2(readdir2("/proc"));
|
|
@@ -20248,7 +20274,7 @@ async function forcePosix(metadata, options) {
|
|
|
20248
20274
|
if (root0 === undefined || root0.uid !== verifiedUid || root0.executable !== expectedExecutable || root0.bootNonce !== metadata.boot_nonce) {
|
|
20249
20275
|
throw new Error("daemon root identity is unavailable for force stop");
|
|
20250
20276
|
}
|
|
20251
|
-
const readTreeSnapshot = options.readSnapshot ?? ((targetPid, expectedExecutable) => options.platform === "darwin" ? readDarwinProcessSnapshot(targetPid, { expectedExecutable }) : readProcessTreeSnapshot(targetPid));
|
|
20277
|
+
const readTreeSnapshot = options.readSnapshot ?? ((targetPid, expectedExecutable) => options.platform === "darwin" ? readDarwinProcessSnapshot(targetPid, { expectedExecutable }) : readProcessTreeSnapshot(targetPid, { expected: tree0ByPid.get(targetPid) }));
|
|
20252
20278
|
const readSnapshot = (targetPid) => readTreeSnapshot(targetPid, expectedExecutable);
|
|
20253
20279
|
const now = options.now ?? (() => performance.now());
|
|
20254
20280
|
const sleep = options.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
|
|
@@ -20274,7 +20300,7 @@ async function forcePosix(metadata, options) {
|
|
|
20274
20300
|
return current;
|
|
20275
20301
|
} catch (error) {
|
|
20276
20302
|
if (missing(error))
|
|
20277
|
-
throw new Error(
|
|
20303
|
+
throw new Error(`daemon process exited before freeze (pid=${expected.pid}, phase=freeze)`, { cause: error });
|
|
20278
20304
|
if (!transient(error))
|
|
20279
20305
|
throw error;
|
|
20280
20306
|
lastError = error;
|
|
@@ -20287,8 +20313,8 @@ async function forcePosix(metadata, options) {
|
|
|
20287
20313
|
try {
|
|
20288
20314
|
if (options.kill(pid, "SIGSTOP") === false)
|
|
20289
20315
|
throw new Error("SIGSTOP returned false");
|
|
20290
|
-
} catch {
|
|
20291
|
-
throw new Error(
|
|
20316
|
+
} catch (error) {
|
|
20317
|
+
throw new Error(`daemon root could not be stopped safely (pid=${pid}, phase=SIGSTOP)`, { cause: error });
|
|
20292
20318
|
}
|
|
20293
20319
|
stoppedCandidates.set(pid, root0);
|
|
20294
20320
|
frozen.set(pid, await waitFrozen(root0, true));
|
|
@@ -20300,8 +20326,8 @@ async function forcePosix(metadata, options) {
|
|
|
20300
20326
|
try {
|
|
20301
20327
|
if (options.kill(snapshot.pid, "SIGSTOP") === false)
|
|
20302
20328
|
throw new Error("SIGSTOP returned false");
|
|
20303
|
-
} catch {
|
|
20304
|
-
throw new Error(
|
|
20329
|
+
} catch (error) {
|
|
20330
|
+
throw new Error(`daemon child could not be stopped safely (pid=${snapshot.pid}, phase=SIGSTOP)`, { cause: error });
|
|
20305
20331
|
}
|
|
20306
20332
|
stoppedCandidates.set(snapshot.pid, snapshot);
|
|
20307
20333
|
frozen.set(snapshot.pid, await waitFrozen(snapshot, false));
|
|
@@ -20330,8 +20356,8 @@ async function forcePosix(metadata, options) {
|
|
|
20330
20356
|
try {
|
|
20331
20357
|
if (options.kill(snapshot.pid, "SIGSTOP") === false)
|
|
20332
20358
|
throw new Error("SIGSTOP returned false");
|
|
20333
|
-
} catch {
|
|
20334
|
-
throw new Error(
|
|
20359
|
+
} catch (error) {
|
|
20360
|
+
throw new Error(`daemon child could not be stopped safely (pid=${snapshot.pid}, phase=SIGSTOP)`, { cause: error });
|
|
20335
20361
|
}
|
|
20336
20362
|
stoppedCandidates.set(snapshot.pid, snapshot);
|
|
20337
20363
|
frozen.set(snapshot.pid, await waitFrozen(snapshot, false));
|
|
@@ -20344,7 +20370,16 @@ async function forcePosix(metadata, options) {
|
|
|
20344
20370
|
if (stableCaptures < 2)
|
|
20345
20371
|
throw new Error("daemon process tree did not stabilize while safely stopped");
|
|
20346
20372
|
const expectedTree = [...frozen.values()];
|
|
20347
|
-
const
|
|
20373
|
+
const sameInstancePresent = (current, expected) => {
|
|
20374
|
+
if (current.pid !== expected.pid)
|
|
20375
|
+
throw new Error("daemon process PID changed");
|
|
20376
|
+
if (current.startTime !== expected.startTime)
|
|
20377
|
+
return false;
|
|
20378
|
+
if (!sameProcessTreeSnapshot({ ...current, ppid: expected.ppid }, expected))
|
|
20379
|
+
throw new Error("daemon process identity changed during exit confirmation");
|
|
20380
|
+
return true;
|
|
20381
|
+
};
|
|
20382
|
+
const oldSnapshotPresent = async (expected, phase = "pre-SIGKILL") => {
|
|
20348
20383
|
try {
|
|
20349
20384
|
if (expected.pid === pid) {
|
|
20350
20385
|
const probe = await options.probeProcess(pid, identity, metadata.boot_nonce);
|
|
@@ -20355,16 +20390,16 @@ async function forcePosix(metadata, options) {
|
|
|
20355
20390
|
const rootSnapshot = await readSnapshot(pid);
|
|
20356
20391
|
if (rootSnapshot.uid !== verifiedUid && sameSnapshotIgnoringUid(rootSnapshot, expected))
|
|
20357
20392
|
throw new Error("daemon root uid changed");
|
|
20358
|
-
return
|
|
20393
|
+
return sameInstancePresent(rootSnapshot, expected);
|
|
20359
20394
|
}
|
|
20360
20395
|
const current = await readSnapshot(expected.pid);
|
|
20361
20396
|
if (current.uid !== verifiedUid && sameSnapshotIgnoringUid(current, expected))
|
|
20362
20397
|
throw new Error("daemon descendant uid changed");
|
|
20363
|
-
return
|
|
20398
|
+
return sameInstancePresent(current, expected);
|
|
20364
20399
|
} catch (error) {
|
|
20365
20400
|
if (missing(error))
|
|
20366
20401
|
return false;
|
|
20367
|
-
throw new Error(
|
|
20402
|
+
throw new Error(`daemon process tree identity became unknown (pid=${expected.pid}, phase=${phase})`, { cause: error });
|
|
20368
20403
|
}
|
|
20369
20404
|
};
|
|
20370
20405
|
const byPid = new Map(expectedTree.map((snapshot) => [snapshot.pid, snapshot]));
|
|
@@ -20385,10 +20420,10 @@ async function forcePosix(metadata, options) {
|
|
|
20385
20420
|
killPath.add(expected.pid);
|
|
20386
20421
|
} catch (error) {
|
|
20387
20422
|
if (error.code === "ESRCH") {
|
|
20388
|
-
if (await oldSnapshotPresent(expected))
|
|
20389
|
-
killErrors.push(new Error(
|
|
20423
|
+
if (await oldSnapshotPresent(expected, "SIGKILL-failure"))
|
|
20424
|
+
killErrors.push(new Error(`daemon descendant remained after SIGKILL failure (pid=${expected.pid})`, { cause: error }));
|
|
20390
20425
|
} else
|
|
20391
|
-
killErrors.push(error);
|
|
20426
|
+
killErrors.push(new Error(`daemon descendant kill failed (pid=${expected.pid}, phase=SIGKILL)`, { cause: error }));
|
|
20392
20427
|
}
|
|
20393
20428
|
}
|
|
20394
20429
|
const rootProbe = await options.probeProcess(pid, identity, metadata.boot_nonce);
|
|
@@ -20406,17 +20441,17 @@ async function forcePosix(metadata, options) {
|
|
|
20406
20441
|
killPath.add(pid);
|
|
20407
20442
|
} catch (error) {
|
|
20408
20443
|
if (error.code === "ESRCH") {
|
|
20409
|
-
if (await oldSnapshotPresent(root0))
|
|
20410
|
-
killErrors.push(new Error(
|
|
20444
|
+
if (await oldSnapshotPresent(root0, "SIGKILL-failure"))
|
|
20445
|
+
killErrors.push(new Error(`daemon root remained after SIGKILL failure (pid=${pid})`, { cause: error }));
|
|
20411
20446
|
} else
|
|
20412
|
-
killErrors.push(error);
|
|
20447
|
+
killErrors.push(new Error(`daemon root kill failed (pid=${pid}, phase=SIGKILL)`, { cause: error }));
|
|
20413
20448
|
}
|
|
20414
20449
|
}
|
|
20415
20450
|
const postKillDeadline = now() + (options.forceWaitMs ?? 1500);
|
|
20416
20451
|
for (;; ) {
|
|
20417
20452
|
let survivor = false;
|
|
20418
20453
|
for (const expected of expectedTree)
|
|
20419
|
-
if (await oldSnapshotPresent(expected))
|
|
20454
|
+
if (await oldSnapshotPresent(expected, "post-SIGKILL"))
|
|
20420
20455
|
survivor = true;
|
|
20421
20456
|
if (!survivor)
|
|
20422
20457
|
break;
|
|
@@ -20446,6 +20481,7 @@ async function forcePosix(metadata, options) {
|
|
|
20446
20481
|
current = await readSnapshot(expected.pid);
|
|
20447
20482
|
if (current === null)
|
|
20448
20483
|
return;
|
|
20484
|
+
current = { ...current, ppid: expected.ppid };
|
|
20449
20485
|
if (current.uid !== verifiedUid && sameSnapshotIgnoringUid(current, expected))
|
|
20450
20486
|
throw new Error("daemon process uid changed while resuming");
|
|
20451
20487
|
if (!sameSnapshotIgnoringState(current, expected) || current.uid !== verifiedUid)
|
|
@@ -21793,7 +21829,7 @@ async function importCommand(options) {
|
|
|
21793
21829
|
// package.json
|
|
21794
21830
|
var package_default = {
|
|
21795
21831
|
name: "@jeffusion/bungee",
|
|
21796
|
-
version: "6.
|
|
21832
|
+
version: "6.17.0",
|
|
21797
21833
|
description: "High-performance reverse proxy server CLI",
|
|
21798
21834
|
type: "module",
|
|
21799
21835
|
bin: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.0",
|
|
4
4
|
"description": "High-performance reverse proxy server CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "bun test"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@jeffusion/bungee-core": "^6.
|
|
17
|
-
"@jeffusion/bungee-types": "^6.
|
|
16
|
+
"@jeffusion/bungee-core": "^6.17.0",
|
|
17
|
+
"@jeffusion/bungee-types": "^6.17.0",
|
|
18
18
|
"cli-progress": "^3.12.0",
|
|
19
19
|
"commander": "^14.0.1"
|
|
20
20
|
},
|