@camstack/system 1.2.311 → 1.2.312

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.
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_child_cap_dispatch = require("./child-cap-dispatch-Be8e2cBP.js");
2
+ const require_child_cap_dispatch = require("./child-cap-dispatch-Dyn_7ezH.js");
3
3
  const require_custom_action_registry = require("./custom-action-registry-acBY3mHA.js");
4
4
  let node_path = require("node:path");
5
5
  node_path = require_chunk.__toESM(node_path);
@@ -346,6 +346,10 @@ for (const sig of [
346
346
  ]) process.on(sig, () => {
347
347
  console.error(`[addon-runner SIGNAL] received ${sig} nodeId=${process.env["CAMSTACK_RUNNER_ID"] ?? "?"}`);
348
348
  });
349
+ require_child_cap_dispatch.startRunnerParentDeathWatchdog(() => {
350
+ console.error(`[addon-runner] "${process.env["CAMSTACK_RUNNER_ID"] ?? "?"}" parent died — killing its process group`);
351
+ if (!require_child_cap_dispatch.killOwnRunnerGroupAfterParentLoss()) process.exit(0);
352
+ });
349
353
  function isRecord(value) {
350
354
  return typeof value === "object" && value !== null && !Array.isArray(value);
351
355
  }
@@ -679,6 +683,7 @@ async function main() {
679
683
  });
680
684
  });
681
685
  const shutdown = async () => {
686
+ if (shuttingDown) return;
682
687
  shuttingDown = true;
683
688
  stopHeapWatch?.();
684
689
  require_child_cap_dispatch.setWorkerNativeCapsChangeListener(null);
@@ -705,13 +710,6 @@ async function main() {
705
710
  process.on("SIGINT", () => {
706
711
  shutdown();
707
712
  });
708
- const initialPpid = process.ppid;
709
- setInterval(() => {
710
- if (process.ppid === 1 && initialPpid !== 1) {
711
- console.error(`[addon-runner] "${nodeId}" parent died (reparented to init) — exiting`);
712
- shutdown();
713
- }
714
- }, 5e3);
715
713
  }
716
714
  main().catch((err) => {
717
715
  console.error(`[addon-runner] Fatal error: ${(0, _camstack_types_addon.errMsg)(err)}`);
@@ -1,4 +1,4 @@
1
- import { B as LocalChildClient, Ct as installManifestNativeDeps, Ht as RUNNER_RSS_BUDGET_ENV, N as createUdsLoggerWithControl, at as getWorkerNativeCapProvider, ct as setWorkerNativeCapsChangeListener, i as installManifestPythonDeps, n as createChildCapDispatch, ot as getWorkerNativeCapSnapshot, pn as emitHeapDiagnosticReport, r as installManifestSystemDeps, s as createUdsAddonContext, tn as startRunnerHeapWatch, ut as validateProviderRegistrations, wt as resolveAddonClass } from "./child-cap-dispatch-BCJjUtXV.mjs";
1
+ import { H as createUdsLoggerWithControl, Mt as installManifestNativeDeps, Nt as resolveAddonClass, Sn as emitHeapDiagnosticReport, Y as LocalChildClient, Zt as RUNNER_RSS_BUDGET_ENV, _t as setWorkerNativeCapsChangeListener, f as installManifestSystemDeps, g as createUdsAddonContext, ht as getWorkerNativeCapSnapshot, i as killOwnRunnerGroupAfterParentLoss, mt as getWorkerNativeCapProvider, n as createChildCapDispatch, p as installManifestPythonDeps, u as startRunnerParentDeathWatchdog, un as startRunnerHeapWatch, yt as validateProviderRegistrations } from "./child-cap-dispatch-CHTiHbsv.mjs";
2
2
  import { t as CustomActionRegistry } from "./custom-action-registry-B4Cf4O_X.mjs";
3
3
  import { register } from "node:module";
4
4
  import * as path$1 from "node:path";
@@ -343,6 +343,10 @@ for (const sig of [
343
343
  ]) process.on(sig, () => {
344
344
  console.error(`[addon-runner SIGNAL] received ${sig} nodeId=${process.env["CAMSTACK_RUNNER_ID"] ?? "?"}`);
345
345
  });
346
+ startRunnerParentDeathWatchdog(() => {
347
+ console.error(`[addon-runner] "${process.env["CAMSTACK_RUNNER_ID"] ?? "?"}" parent died — killing its process group`);
348
+ if (!killOwnRunnerGroupAfterParentLoss()) process.exit(0);
349
+ });
346
350
  function isRecord(value) {
347
351
  return typeof value === "object" && value !== null && !Array.isArray(value);
348
352
  }
@@ -676,6 +680,7 @@ async function main() {
676
680
  });
677
681
  });
678
682
  const shutdown = async () => {
683
+ if (shuttingDown) return;
679
684
  shuttingDown = true;
680
685
  stopHeapWatch?.();
681
686
  setWorkerNativeCapsChangeListener(null);
@@ -702,13 +707,6 @@ async function main() {
702
707
  process.on("SIGINT", () => {
703
708
  shutdown();
704
709
  });
705
- const initialPpid = process.ppid;
706
- setInterval(() => {
707
- if (process.ppid === 1 && initialPpid !== 1) {
708
- console.error(`[addon-runner] "${nodeId}" parent died (reparented to init) — exiting`);
709
- shutdown();
710
- }
711
- }, 5e3);
712
710
  }
713
711
  main().catch((err) => {
714
712
  console.error(`[addon-runner] Fatal error: ${errMsg(err)}`);
@@ -4,6 +4,7 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
6
  const require_dist = require("../../dist-CkRwnhbo.js");
7
+ const require_proc_stat = require("../../proc-stat-DL-WUOhl.js");
7
8
  let node_fs_promises = require("node:fs/promises");
8
9
  let node_fs = require("node:fs");
9
10
  node_fs = require_chunk.__toESM(node_fs);
@@ -2125,7 +2126,7 @@ var NativeMetricsProvider = class {
2125
2126
  return getCpuTemperatureInternal();
2126
2127
  }
2127
2128
  async getProcessStats(input) {
2128
- const { getPidStats } = await Promise.resolve().then(() => require("../../resource-monitor-LVE1BoLs.js")).then((n) => n.resource_monitor_exports);
2129
+ const { getPidStats } = await Promise.resolve().then(() => require("../../resource-monitor-DzNn_IZK.js")).then((n) => n.resource_monitor_exports);
2129
2130
  const raw = await getPidStats(input.pids);
2130
2131
  const result = [];
2131
2132
  for (const [pid, s] of raw) result.push({
@@ -2461,95 +2462,6 @@ function execAsync(cmd, args, timeoutMs = 5e3) {
2461
2462
  });
2462
2463
  });
2463
2464
  }
2464
- /**
2465
- * Parse one `/proc/<pid>/stat` line. `null` for a line that does not parse —
2466
- * a process that exited between the readdir and the read leaves a truncated
2467
- * or empty file, and that is normal, not an error.
2468
- */
2469
- function parseProcStat(line) {
2470
- const close = line.lastIndexOf(")");
2471
- const open = line.indexOf("(");
2472
- if (close < 0 || open < 0 || close < open) return null;
2473
- const pid = Number(line.slice(0, open).trim());
2474
- const comm = line.slice(open + 1, close);
2475
- const rest = line.slice(close + 1).trim().split(/\s+/);
2476
- const state = rest[0];
2477
- const ppid = Number(rest[1]);
2478
- const pgid = Number(rest[2]);
2479
- const utime = Number(rest[11]);
2480
- const stime = Number(rest[12]);
2481
- const startTicks = Number(rest[19]);
2482
- const rssPages = Number(rest[21]);
2483
- if (state === void 0 || state === "") return null;
2484
- if (![
2485
- pid,
2486
- ppid,
2487
- pgid,
2488
- utime,
2489
- stime,
2490
- startTicks,
2491
- rssPages
2492
- ].every(Number.isFinite)) return null;
2493
- return {
2494
- pid,
2495
- comm,
2496
- state,
2497
- ppid,
2498
- pgid,
2499
- ticks: utime + stime,
2500
- startTicks,
2501
- rssPages
2502
- };
2503
- }
2504
- function statusKb(status, key) {
2505
- const match = status.match(new RegExp(`^${key}:\\s+(\\d+)`, "m"));
2506
- return match ? parseInt(match[1], 10) * 1024 : void 0;
2507
- }
2508
- /** Read `VmRSS` / `RssAnon` / `RssFile` (kB in the file) out of `/proc/<pid>/status`. */
2509
- function parseProcStatusRss(status) {
2510
- return {
2511
- rssBytes: statusKb(status, "VmRSS"),
2512
- privateBytes: statusKb(status, "RssAnon"),
2513
- sharedBytes: statusKb(status, "RssFile")
2514
- };
2515
- }
2516
- /** Seconds the process has been alive — `ps etime`, whole seconds. */
2517
- function elapsedSecSince(input) {
2518
- return Math.max(0, Math.floor(input.uptimeSec - input.startTicks / 100));
2519
- }
2520
- /**
2521
- * `ps pcpu`: CPU time over elapsed time, as a percentage with one decimal.
2522
- *
2523
- * This is deliberately the LIFETIME average `ps` prints, not an instantaneous
2524
- * rate: the columns fed from it have always shown that quantity, and the
2525
- * instantaneous split is a different number with a different owner
2526
- * (`cpuMainPercent` / `cpuGcPercent` from `thread-cpu-sampler.ts`). A process
2527
- * with no elapsed window yet reports 0, never a division by zero.
2528
- */
2529
- function lifetimeCpuPercent(input) {
2530
- const elapsedSec = input.uptimeSec - input.startTicks / 100;
2531
- if (!(elapsedSec > 0)) return 0;
2532
- const cpuSec = input.ticks / 100;
2533
- return Math.round(cpuSec / elapsedSec * 1e3) / 10;
2534
- }
2535
- var PID_RE = /^\d+$/;
2536
- var nodeProcReader = {
2537
- listPids: async () => (await (0, node_fs_promises.readdir)("/proc")).filter((entry) => PID_RE.test(entry)).map((entry) => Number(entry)),
2538
- readStat: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/stat`, "latin1"),
2539
- readStatus: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/status`, "latin1"),
2540
- readCmdline: (pid) => (0, node_fs_promises.readFile)(`/proc/${pid}/cmdline`, "latin1"),
2541
- readUptimeSec: async () => {
2542
- const [first] = (await (0, node_fs_promises.readFile)("/proc/uptime", "latin1")).trim().split(/\s+/);
2543
- const seconds = Number(first);
2544
- if (!Number.isFinite(seconds)) throw new Error(`/proc/uptime unreadable: ${String(first)}`);
2545
- return seconds;
2546
- }
2547
- };
2548
- /** `ps command=`: argv joined by spaces, or `[comm]` when there is no argv. */
2549
- function commandFromCmdline(cmdline, comm) {
2550
- const joined = cmdline.split("\0").filter((part) => part.length > 0).join(" ");
2551
- return joined.length > 0 ? joined : `[${comm}]`;
2552
- }
2553
2465
  //#endregion
2554
2466
  //#region src/builtins/native-metrics/proc-process-table.ts
2555
2467
  /**
@@ -2581,28 +2493,28 @@ async function readProcRow(pid, uptimeSec, reader) {
2581
2493
  } catch {
2582
2494
  return null;
2583
2495
  }
2584
- const parsed = parseProcStat(stat);
2496
+ const parsed = require_proc_stat.parseProcStat(stat);
2585
2497
  if (parsed === null) return null;
2586
- const rss = parseProcStatusRss(status);
2498
+ const rss = require_proc_stat.parseProcStatusRss(status);
2587
2499
  return {
2588
2500
  pid: parsed.pid,
2589
2501
  ppid: parsed.ppid,
2590
2502
  pgid: parsed.pgid,
2591
- cpuPercent: lifetimeCpuPercent({
2503
+ cpuPercent: require_proc_stat.lifetimeCpuPercent({
2592
2504
  ticks: parsed.ticks,
2593
2505
  startTicks: parsed.startTicks,
2594
2506
  uptimeSec
2595
2507
  }),
2596
2508
  memoryRssBytes: rss.rssBytes ?? 0,
2597
- uptimeSec: elapsedSecSince({
2509
+ uptimeSec: require_proc_stat.elapsedSecSince({
2598
2510
  startTicks: parsed.startTicks,
2599
2511
  uptimeSec
2600
2512
  }),
2601
- command: commandFromCmdline(cmdline, parsed.comm)
2513
+ command: require_proc_stat.commandFromCmdline(cmdline, parsed.comm)
2602
2514
  };
2603
2515
  }
2604
2516
  /** Every process in `/proc`, as the rows `ps -eo …` would have printed. */
2605
- async function readProcProcessTable(reader = nodeProcReader) {
2517
+ async function readProcProcessTable(reader = require_proc_stat.nodeProcReader) {
2606
2518
  const [pids, uptimeSec] = await Promise.all([reader.listPids(), reader.readUptimeSec()]);
2607
2519
  return (await Promise.all(pids.map((pid) => readProcRow(pid, uptimeSec, reader)))).filter((row) => row !== null);
2608
2520
  }
@@ -2657,7 +2569,7 @@ async function spawnPsTable() {
2657
2569
  }
2658
2570
  var defaultDeps = {
2659
2571
  platform: (0, node_os.platform)(),
2660
- reader: nodeProcReader,
2572
+ reader: require_proc_stat.nodeProcReader,
2661
2573
  spawnPs: spawnPsTable
2662
2574
  };
2663
2575
  /**
@@ -3531,7 +3443,3 @@ var NativeMetricsAddon = class NativeMetricsAddon extends require_dist.BaseAddon
3531
3443
  //#endregion
3532
3444
  exports.NativeMetricsProvider = NativeMetricsProvider;
3533
3445
  exports.default = NativeMetricsAddon;
3534
- exports.lifetimeCpuPercent = lifetimeCpuPercent;
3535
- exports.nodeProcReader = nodeProcReader;
3536
- exports.parseProcStat = parseProcStat;
3537
- exports.parseProcStatusRss = parseProcStatusRss;
@@ -1,4 +1,5 @@
1
1
  import { Dt as foldSnapshotByFunction, Jt as metricsProviderCapability, Wn as createEvent, an as reducePoints, ir as EventCategory, jn as BaseAddon, kn as errMsg, on as resolveBucketMs } from "../../dist-Cj7pJmXq.mjs";
2
+ import { a as parseProcStat, i as nodeProcReader, n as elapsedSecSince, o as parseProcStatusRss, r as lifetimeCpuPercent, t as commandFromCmdline } from "../../proc-stat-CbC55Kqi.mjs";
2
3
  import { access, readFile, readdir } from "node:fs/promises";
3
4
  import * as fs from "node:fs";
4
5
  import { constants, readFileSync } from "node:fs";
@@ -2120,7 +2121,7 @@ var NativeMetricsProvider = class {
2120
2121
  return getCpuTemperatureInternal();
2121
2122
  }
2122
2123
  async getProcessStats(input) {
2123
- const { getPidStats } = await import("../../resource-monitor-Vp0bPV3U.mjs").then((n) => n.r);
2124
+ const { getPidStats } = await import("../../resource-monitor-B1v6E07R.mjs").then((n) => n.r);
2124
2125
  const raw = await getPidStats(input.pids);
2125
2126
  const result = [];
2126
2127
  for (const [pid, s] of raw) result.push({
@@ -2456,95 +2457,6 @@ function execAsync(cmd, args, timeoutMs = 5e3) {
2456
2457
  });
2457
2458
  });
2458
2459
  }
2459
- /**
2460
- * Parse one `/proc/<pid>/stat` line. `null` for a line that does not parse —
2461
- * a process that exited between the readdir and the read leaves a truncated
2462
- * or empty file, and that is normal, not an error.
2463
- */
2464
- function parseProcStat(line) {
2465
- const close = line.lastIndexOf(")");
2466
- const open = line.indexOf("(");
2467
- if (close < 0 || open < 0 || close < open) return null;
2468
- const pid = Number(line.slice(0, open).trim());
2469
- const comm = line.slice(open + 1, close);
2470
- const rest = line.slice(close + 1).trim().split(/\s+/);
2471
- const state = rest[0];
2472
- const ppid = Number(rest[1]);
2473
- const pgid = Number(rest[2]);
2474
- const utime = Number(rest[11]);
2475
- const stime = Number(rest[12]);
2476
- const startTicks = Number(rest[19]);
2477
- const rssPages = Number(rest[21]);
2478
- if (state === void 0 || state === "") return null;
2479
- if (![
2480
- pid,
2481
- ppid,
2482
- pgid,
2483
- utime,
2484
- stime,
2485
- startTicks,
2486
- rssPages
2487
- ].every(Number.isFinite)) return null;
2488
- return {
2489
- pid,
2490
- comm,
2491
- state,
2492
- ppid,
2493
- pgid,
2494
- ticks: utime + stime,
2495
- startTicks,
2496
- rssPages
2497
- };
2498
- }
2499
- function statusKb(status, key) {
2500
- const match = status.match(new RegExp(`^${key}:\\s+(\\d+)`, "m"));
2501
- return match ? parseInt(match[1], 10) * 1024 : void 0;
2502
- }
2503
- /** Read `VmRSS` / `RssAnon` / `RssFile` (kB in the file) out of `/proc/<pid>/status`. */
2504
- function parseProcStatusRss(status) {
2505
- return {
2506
- rssBytes: statusKb(status, "VmRSS"),
2507
- privateBytes: statusKb(status, "RssAnon"),
2508
- sharedBytes: statusKb(status, "RssFile")
2509
- };
2510
- }
2511
- /** Seconds the process has been alive — `ps etime`, whole seconds. */
2512
- function elapsedSecSince(input) {
2513
- return Math.max(0, Math.floor(input.uptimeSec - input.startTicks / 100));
2514
- }
2515
- /**
2516
- * `ps pcpu`: CPU time over elapsed time, as a percentage with one decimal.
2517
- *
2518
- * This is deliberately the LIFETIME average `ps` prints, not an instantaneous
2519
- * rate: the columns fed from it have always shown that quantity, and the
2520
- * instantaneous split is a different number with a different owner
2521
- * (`cpuMainPercent` / `cpuGcPercent` from `thread-cpu-sampler.ts`). A process
2522
- * with no elapsed window yet reports 0, never a division by zero.
2523
- */
2524
- function lifetimeCpuPercent(input) {
2525
- const elapsedSec = input.uptimeSec - input.startTicks / 100;
2526
- if (!(elapsedSec > 0)) return 0;
2527
- const cpuSec = input.ticks / 100;
2528
- return Math.round(cpuSec / elapsedSec * 1e3) / 10;
2529
- }
2530
- var PID_RE = /^\d+$/;
2531
- var nodeProcReader = {
2532
- listPids: async () => (await readdir("/proc")).filter((entry) => PID_RE.test(entry)).map((entry) => Number(entry)),
2533
- readStat: (pid) => readFile(`/proc/${pid}/stat`, "latin1"),
2534
- readStatus: (pid) => readFile(`/proc/${pid}/status`, "latin1"),
2535
- readCmdline: (pid) => readFile(`/proc/${pid}/cmdline`, "latin1"),
2536
- readUptimeSec: async () => {
2537
- const [first] = (await readFile("/proc/uptime", "latin1")).trim().split(/\s+/);
2538
- const seconds = Number(first);
2539
- if (!Number.isFinite(seconds)) throw new Error(`/proc/uptime unreadable: ${String(first)}`);
2540
- return seconds;
2541
- }
2542
- };
2543
- /** `ps command=`: argv joined by spaces, or `[comm]` when there is no argv. */
2544
- function commandFromCmdline(cmdline, comm) {
2545
- const joined = cmdline.split("\0").filter((part) => part.length > 0).join(" ");
2546
- return joined.length > 0 ? joined : `[${comm}]`;
2547
- }
2548
2460
  //#endregion
2549
2461
  //#region src/builtins/native-metrics/proc-process-table.ts
2550
2462
  /**
@@ -3524,4 +3436,4 @@ var NativeMetricsAddon = class NativeMetricsAddon extends BaseAddon {
3524
3436
  }
3525
3437
  };
3526
3438
  //#endregion
3527
- export { NativeMetricsProvider as a, NativeMetricsAddon as default, parseProcStatusRss as i, nodeProcReader as n, parseProcStat as r, lifetimeCpuPercent as t };
3439
+ export { NativeMetricsAddon as default, NativeMetricsProvider as t };