mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(verify): preserve Linux descendant records with multiline names (#11949)
* fix(verify): preserve Linux descendant records with multiline names * fix(verify): load the stat parser without changing stderr --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
40f9269284
commit
954bcd6082
2 files changed
+36
-13
No files matched your search
@@ -193,7 +193,15 @@ const processSnapshot = async () => {
|
||||
return posixProcessSnapshot();
|
||||
};
|
||||
|
||||
/** @type {Promise<typeof import("../../src/process/LinuxProcessStat.js")> | undefined} */
|
||||
let linuxStatParser;
|
||||
|
||||
const linuxProcessSnapshot = async () => {
|
||||
// The pinned Node can strip this leaf module without a transform or loader.
|
||||
linuxStatParser ??= import(
|
||||
new URL("../../src/process/LinuxProcessStat.ts", import.meta.url).href
|
||||
);
|
||||
const { parseLinuxProcessStat } = await linuxStatParser;
|
||||
const entries = await readdir("/proc", { withFileTypes: true });
|
||||
/** @type {ProcessMember[]} */
|
||||
const members = [];
|
||||
@@ -201,13 +209,16 @@ const linuxProcessSnapshot = async () => {
|
||||
if (!entry.isDirectory() || !/^\d+$/u.test(entry.name)) continue;
|
||||
try {
|
||||
const stat = await readFile(`/proc/${entry.name}/stat`, "utf8");
|
||||
const match = /^\d+ \(.*\) (\S) (\d+) (\d+) /u.exec(stat);
|
||||
if (match === null || match[1] === "Z") continue;
|
||||
members.push({
|
||||
pid: Number(entry.name),
|
||||
parentPid: Number(match[2]),
|
||||
processGroupId: Number(match[3]),
|
||||
});
|
||||
const parsed = parseLinuxProcessStat(stat);
|
||||
if (
|
||||
parsed === undefined ||
|
||||
parsed.pid !== Number(entry.name) ||
|
||||
parsed.lifecycle === "zombie" ||
|
||||
parsed.lifecycle === "dead"
|
||||
)
|
||||
continue;
|
||||
const { pid, parentPid, processGroupId } = parsed;
|
||||
members.push({ pid, parentPid, processGroupId });
|
||||
} catch {
|
||||
// Processes can exit while /proc is being sampled.
|
||||
}
|
||||
|
||||
@@ -49,13 +49,18 @@ describe("verifier run identity", { concurrent: false }, () => {
|
||||
}
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")(
|
||||
"reports token-verified live descendants",
|
||||
async () => {
|
||||
it
|
||||
.runIf(process.platform !== "win32")
|
||||
.each([
|
||||
undefined,
|
||||
...(process.platform === "linux" ? ["fixture\nworker"] : []),
|
||||
])(
|
||||
"reports token-verified live descendants with display name %j",
|
||||
async (displayName) => {
|
||||
const previousRunId = process.env.REA_PROCESS_RUN_ID;
|
||||
delete process.env.REA_PROCESS_RUN_ID;
|
||||
const run = createVerifierRun();
|
||||
const child = spawnReadyChild(process.env);
|
||||
const child = spawnReadyChild(process.env, displayName);
|
||||
try {
|
||||
await childReady(child);
|
||||
const completed = await completeVerifierRun(run);
|
||||
@@ -106,10 +111,17 @@ describe("verifier run identity", { concurrent: false }, () => {
|
||||
);
|
||||
});
|
||||
|
||||
const spawnReadyChild = (env: NodeJS.ProcessEnv): ChildProcess =>
|
||||
const spawnReadyChild = (
|
||||
env: NodeJS.ProcessEnv,
|
||||
displayName?: string,
|
||||
): ChildProcess =>
|
||||
spawn(
|
||||
process.execPath,
|
||||
["-e", "process.stdout.write('ready'); setInterval(() => {}, 1000)"],
|
||||
[
|
||||
"-e",
|
||||
`if (process.argv[1] !== undefined) process.title = process.argv[1]; process.stdout.write("ready"); setInterval(() => {}, 1000)`,
|
||||
...(displayName === undefined ? [] : [displayName]),
|
||||
],
|
||||
{ env, stdio: ["ignore", "pipe", "ignore"] },
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user