@descryy/runtime-orchestrator 0.4.7 → 0.4.9
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 +7 -7
- package/dist/attach-to-running-jvm-process.d.ts +0 -86
- package/dist/attach-to-running-jvm-process.d.ts.map +0 -1
- package/dist/attach-to-running-jvm-process.js +0 -408
- package/dist/attach-to-running-jvm-process.js.map +0 -1
- package/dist/attach-to-running-node-process.d.ts +0 -80
- package/dist/attach-to-running-node-process.d.ts.map +0 -1
- package/dist/attach-to-running-node-process.js +0 -290
- package/dist/attach-to-running-node-process.js.map +0 -1
- package/dist/attach-to-running-process.d.ts +0 -83
- package/dist/attach-to-running-process.d.ts.map +0 -1
- package/dist/attach-to-running-process.js +0 -86
- package/dist/attach-to-running-process.js.map +0 -1
- package/dist/cdp-client.d.ts +0 -27
- package/dist/cdp-client.d.ts.map +0 -1
- package/dist/cdp-client.js +0 -98
- package/dist/cdp-client.js.map +0 -1
- package/dist/cgroup-partial-restriction.d.ts +0 -80
- package/dist/cgroup-partial-restriction.d.ts.map +0 -1
- package/dist/cgroup-partial-restriction.js +0 -189
- package/dist/cgroup-partial-restriction.js.map +0 -1
- package/dist/collector-version.d.ts +0 -7
- package/dist/collector-version.d.ts.map +0 -1
- package/dist/collector-version.js +0 -9
- package/dist/collector-version.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/instrumented-execution.d.ts +0 -129
- package/dist/instrumented-execution.d.ts.map +0 -1
- package/dist/instrumented-execution.js +0 -547
- package/dist/instrumented-execution.js.map +0 -1
- package/dist/jvm-agent/build.d.ts +0 -48
- package/dist/jvm-agent/build.d.ts.map +0 -1
- package/dist/jvm-agent/build.js +0 -129
- package/dist/jvm-agent/build.js.map +0 -1
- package/dist/polling-output-source.d.ts +0 -43
- package/dist/polling-output-source.d.ts.map +0 -1
- package/dist/polling-output-source.js +0 -64
- package/dist/polling-output-source.js.map +0 -1
- package/dist/profile-backend-observation.d.ts +0 -67
- package/dist/profile-backend-observation.d.ts.map +0 -1
- package/dist/profile-backend-observation.js +0 -107
- package/dist/profile-backend-observation.js.map +0 -1
- package/dist/respawn-and-supervise.d.ts +0 -86
- package/dist/respawn-and-supervise.d.ts.map +0 -1
- package/dist/respawn-and-supervise.js +0 -171
- package/dist/respawn-and-supervise.js.map +0 -1
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Respawn-and-supervise: a separate execution mode next to attach mode, not a
|
|
3
|
-
* change to attach mode itself.
|
|
4
|
-
*
|
|
5
|
-
* **The tradeoff, stated up front — must never apply silently.** Attach mode
|
|
6
|
-
* reaches an already-running, unconfined process; there is no honest way to
|
|
7
|
-
* retroactively sandbox it (`sandbox.ts`). This module doesn't try — it kills the
|
|
8
|
-
* attached target and spawns a fresh equivalent via the existing `spawnProcess()`,
|
|
9
|
-
* which gets full sandboxing for anything it spawns. Price: in-memory state, open
|
|
10
|
-
* connections, anything unpersisted is gone the moment the old process is killed.
|
|
11
|
-
* A caller must choose this explicitly — nothing upgrades an attach into a respawn
|
|
12
|
-
* on its own.
|
|
13
|
-
*
|
|
14
|
-
* **How this learns what to respawn.** Follows RT-032's "declared, never inferred"
|
|
15
|
-
* precedent: caller-declared (`source: "caller-declared"`) is the recommended,
|
|
16
|
-
* default path. `/proc/<pid>/cmdline` readback is a real but best-effort,
|
|
17
|
-
* opt-in-only fallback (`inferRespawnCommandFromProc`), labelled `source:
|
|
18
|
-
* "proc-cmdline-inferred"` so it's never mistaken for a declaration.
|
|
19
|
-
*
|
|
20
|
-
* **Killing the old process.** Doesn't assume ownership of the target's process
|
|
21
|
-
* group — it may not even be its own group leader — so this signals the individual
|
|
22
|
-
* pid only (SIGTERM, then SIGKILL after `gracePeriodMs`), not `spawnProcess`'s
|
|
23
|
-
* group-kill escape hatch (`signalGroup`), which is only valid for a group it
|
|
24
|
-
* created itself.
|
|
25
|
-
*/
|
|
26
|
-
import { spawnProcess } from "@descryy/runtime-controller";
|
|
27
|
-
import { readFileSync, readlinkSync } from "node:fs";
|
|
28
|
-
import { isProcessAlive } from "./attach-to-running-process.js";
|
|
29
|
-
const DEFAULT_GRACE_PERIOD_MS = 5000;
|
|
30
|
-
function sleep(ms) {
|
|
31
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Waits until `isProcessAlive(pid)` is false or `deadlineMs` elapses.
|
|
35
|
-
* Returns whether the process was confirmed dead.
|
|
36
|
-
*/
|
|
37
|
-
async function waitForDeath(pid, deadlineMs) {
|
|
38
|
-
const deadline = Date.now() + deadlineMs;
|
|
39
|
-
while (Date.now() < deadline) {
|
|
40
|
-
if (!isProcessAlive(pid))
|
|
41
|
-
return true;
|
|
42
|
-
await sleep(20);
|
|
43
|
-
}
|
|
44
|
-
return !isProcessAlive(pid);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Kills `pid` directly (not its process group, see file header), escalating
|
|
48
|
-
* SIGTERM to SIGKILL after `gracePeriodMs`. Throws if it survives even SIGKILL
|
|
49
|
-
* (unreapable zombie, or a permission boundary) rather than reporting an unobserved
|
|
50
|
-
* success.
|
|
51
|
-
*/
|
|
52
|
-
async function killTarget(pid, gracePeriodMs) {
|
|
53
|
-
if (!isProcessAlive(pid))
|
|
54
|
-
return { killedViaSigkill: false };
|
|
55
|
-
try {
|
|
56
|
-
process.kill(pid, "SIGTERM");
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// race: already gone between the isProcessAlive check and this signal
|
|
60
|
-
}
|
|
61
|
-
if (await waitForDeath(pid, gracePeriodMs))
|
|
62
|
-
return { killedViaSigkill: false };
|
|
63
|
-
try {
|
|
64
|
-
process.kill(pid, "SIGKILL");
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// same race, at the SIGKILL stage
|
|
68
|
-
}
|
|
69
|
-
const dead = await waitForDeath(pid, Math.max(gracePeriodMs, 2000));
|
|
70
|
-
if (!dead) {
|
|
71
|
-
throw new Error(`respawnAndSupervise: pid ${String(pid)} did not exit even after SIGKILL -- refusing to report a kill that was not observed. ` +
|
|
72
|
-
"This can happen for a zombie this process cannot reap (owned by a different parent) or a permission boundary this caller's uid cannot cross.");
|
|
73
|
-
}
|
|
74
|
-
return { killedViaSigkill: true };
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Kills the process at `options.targetPid` and spawns a fresh, supervised,
|
|
78
|
-
* optionally sandboxed replacement via `spawnProcess()`.
|
|
79
|
-
*
|
|
80
|
-
* Not a silent behavior change to attach mode — reached only by explicit call,
|
|
81
|
-
* never an automatic upgrade path. `ATTACH_MODE_SCOPE_DISCLOSURE` still governs
|
|
82
|
-
* attach mode itself regardless.
|
|
83
|
-
*
|
|
84
|
-
* Throws if `targetPid` isn't alive at call time, matching `attachToRunningProcess`'s
|
|
85
|
-
* refuse-rather-than-operate-on-nonexistent-target contract.
|
|
86
|
-
*/
|
|
87
|
-
export async function respawnAndSupervise(options) {
|
|
88
|
-
if (!isProcessAlive(options.targetPid)) {
|
|
89
|
-
throw new Error(`respawnAndSupervise: pid ${String(options.targetPid)} for "${options.processId}" is not running -- ` +
|
|
90
|
-
"respawn-and-supervise requires a target that already exists, the same as attach mode does.");
|
|
91
|
-
}
|
|
92
|
-
const { killedViaSigkill } = await killTarget(options.targetPid, options.gracePeriodMs ?? DEFAULT_GRACE_PERIOD_MS);
|
|
93
|
-
const managedProcess = spawnProcess({
|
|
94
|
-
processId: options.processId,
|
|
95
|
-
command: options.respawn.command,
|
|
96
|
-
args: options.respawn.args ?? [],
|
|
97
|
-
cwd: options.respawn.cwd,
|
|
98
|
-
...(options.respawn.env === undefined ? {} : { env: options.respawn.env }),
|
|
99
|
-
...(options.serviceName === undefined ? {} : { serviceName: options.serviceName }),
|
|
100
|
-
...(options.port === undefined ? {} : { port: options.port }),
|
|
101
|
-
...(options.resourceLimits === undefined ? {} : { resourceLimits: options.resourceLimits }),
|
|
102
|
-
...(options.filesystemPolicy === undefined ? {} : { filesystemPolicy: options.filesystemPolicy }),
|
|
103
|
-
...(options.networkPolicy === undefined ? {} : { networkPolicy: options.networkPolicy }),
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
managedProcess,
|
|
107
|
-
killedPid: options.targetPid,
|
|
108
|
-
killedViaSigkill,
|
|
109
|
-
respawnSource: options.respawn.source,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Opt-in, best-effort convenience — never the default. Reads `/proc/<pid>/cmdline`,
|
|
114
|
-
* `/cwd` and `/environ` to reconstruct a `RespawnCommand`, labelled `source:
|
|
115
|
-
* "proc-cmdline-inferred"` so it's never mistaken for a caller declaration.
|
|
116
|
-
*
|
|
117
|
-
* Disclosed limitations: Linux-only; `/proc/<pid>/environ` reflects only the
|
|
118
|
-
* environment at `execve()` time, so env vars set programmatically after exec are
|
|
119
|
-
* invisible; already-open file descriptors (inherited sockets/pipes) have no
|
|
120
|
-
* command-line representation and can't be recovered. Returns `null` — never
|
|
121
|
-
* throws, never guesses partially — when cmdline can't be read or is empty.
|
|
122
|
-
*/
|
|
123
|
-
export function inferRespawnCommandFromProc(pid, platform = process.platform) {
|
|
124
|
-
if (platform !== "linux")
|
|
125
|
-
return null;
|
|
126
|
-
let cmdlineRaw;
|
|
127
|
-
try {
|
|
128
|
-
cmdlineRaw = readFileSync(`/proc/${String(pid)}/cmdline`, "utf8");
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
// NUL-separated with a trailing NUL; drop the empty tail entry
|
|
134
|
-
const parts = cmdlineRaw.split("\0").filter((part) => part !== "");
|
|
135
|
-
if (parts.length === 0)
|
|
136
|
-
return null;
|
|
137
|
-
const [command, ...args] = parts;
|
|
138
|
-
if (command === undefined)
|
|
139
|
-
return null;
|
|
140
|
-
let cwd;
|
|
141
|
-
try {
|
|
142
|
-
cwd = readlinkSync(`/proc/${String(pid)}/cwd`);
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
let env;
|
|
148
|
-
try {
|
|
149
|
-
const environRaw = readFileSync(`/proc/${String(pid)}/environ`, "utf8");
|
|
150
|
-
env = {};
|
|
151
|
-
for (const entry of environRaw.split("\0").filter((part) => part !== "")) {
|
|
152
|
-
const eq = entry.indexOf("=");
|
|
153
|
-
if (eq === -1)
|
|
154
|
-
continue;
|
|
155
|
-
env[entry.slice(0, eq)] = entry.slice(eq + 1);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
// environ is commonly permission-denied across uids even when cmdline/cwd
|
|
160
|
-
// are readable; degrade to no env rather than failing the whole inference
|
|
161
|
-
env = undefined;
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
command,
|
|
165
|
-
args,
|
|
166
|
-
cwd,
|
|
167
|
-
...(env === undefined ? {} : { env }),
|
|
168
|
-
source: "proc-cmdline-inferred",
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=respawn-and-supervise.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"respawn-and-supervise.js","sourceRoot":"","sources":["../src/respawn-and-supervise.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAiD,MAAM,6BAA6B,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAyChE,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,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