diff --git a/runner/lib/helpers/procsfs.js b/runner/lib/helpers/procsfs.js index b20ee41..a28a608 100644 --- a/runner/lib/helpers/procsfs.js +++ b/runner/lib/helpers/procsfs.js @@ -49,6 +49,7 @@ export const makeProcfsHelper = ({ fs, spawn, startPid = process.pid }) => { return parseInt(res.toString(bufferOptions.encoding), 10); })(); + userHertzP.catch(() => {}); /** @typedef {string[]} ProcStat */ /** @@ -106,6 +107,7 @@ export const makeProcfsHelper = ({ fs, spawn, startPid = process.pid }) => { const getStartTicks = (stat) => parseInt(stat[21], 10); const startTicksOriginP = getStat(startPid).then(getStartTicks); + startTicksOriginP.catch(() => {}); // TODO: Use a WeakValueMap /** @type {Map} */ diff --git a/runner/lib/main.js b/runner/lib/main.js index 00a0f0f..8ad5305 100644 --- a/runner/lib/main.js +++ b/runner/lib/main.js @@ -303,7 +303,7 @@ const main = async (progName, rawArgs, powers) => { /** @type {Promise[]} */ const pendingBackups = []; const timeSource = makeTimeSource({ performance }); - const cpuTimeOffset = await getCPUTimeOffset(); + const cpuTimeOffset = await getCPUTimeOffset().catch(() => 0); const cpuTimeSource = timeSource.shift(0 - cpuTimeOffset); let currentStageTimeSource = timeSource; @@ -505,9 +505,11 @@ const main = async (progName, rawArgs, powers) => { logPerfEvent('chain-stopped'); }); - currentStageTimeSource = cpuTimeSource.shift( - runChainResult.processInfo.startTimestamp, - ); + if (runChainResult.processInfo) { + currentStageTimeSource = cpuTimeSource.shift( + runChainResult.processInfo.startTimestamp, + ); + } const slogLinesStream = Readable.from(runChainResult.slogLines); const slogLines = new PassThrough({ objectMode: true }); @@ -561,19 +563,21 @@ const main = async (progName, rawArgs, powers) => { }, }; - const chainMonitor = makeChainMonitor( - { - processInfo: runChainResult.processInfo, - storageLocation: chainStorageLocation, - }, - { - ...makeConsole('monitor-chain', out, err), - logPerfEvent, - cpuTimeSource, - dirDiskUsage, - }, - ); - chainMonitor.start(monitorInterval); + const chainMonitor = + runChainResult.processInfo && + makeChainMonitor( + { + processInfo: runChainResult.processInfo, + storageLocation: chainStorageLocation, + }, + { + ...makeConsole('monitor-chain', out, err), + logPerfEvent, + cpuTimeSource, + dirDiskUsage, + }, + ); + chainMonitor?.start(monitorInterval); const slogMonitorDone = monitorSlog( { slogLines }, @@ -616,7 +620,7 @@ const main = async (progName, rawArgs, powers) => { async () => aggregateTryFinally( async () => { - chainMonitor.stop(); + chainMonitor?.stop(); if (!chainExited) { stageConsole.log('Stopping chain'); diff --git a/runner/lib/monitor/loadgen-monitor.js b/runner/lib/monitor/loadgen-monitor.js index ee14a5f..291042a 100644 --- a/runner/lib/monitor/loadgen-monitor.js +++ b/runner/lib/monitor/loadgen-monitor.js @@ -1,12 +1,16 @@ /** @typedef {import('../stats/types.js').StageStats} StageStats */ +/** + * @typedef {object} TaskNotifier + * @property {(task: string, seq: number) => void} start + * @property {(task: string, seq: number, success: boolean) => void} finish + */ + /** * @param {import("../tasks/types.js").RunLoadgenInfo} loadgenInfo * @param {object} param1 * @param {StageStats} param1.stats - * @param {object} [param1.notifier] - * @param {(task: string, seq: number) => void} [param1.notifier.start] - * @param {(task: string, seq: number, success: boolean) => void} [param1.notifier.finish] + * @param {TaskNotifier} [param1.notifier] * @param {Console} param1.console */ export const monitorLoadgen = async ( diff --git a/runner/lib/tasks/local-chain.js b/runner/lib/tasks/local-chain.js index 48ebd67..a70cbc4 100644 --- a/runner/lib/tasks/local-chain.js +++ b/runner/lib/tasks/local-chain.js @@ -334,7 +334,7 @@ export const makeTasks = ({ const processInfo = await getProcessInfo( /** @type {number} */ (chainCp.pid), - ); + ).catch(() => undefined); return harden({ stop, @@ -576,7 +576,7 @@ export const makeTasks = ({ const processInfo = await getProcessInfo( /** @type {number} */ (soloCp.pid), - ); + ).catch(() => undefined); const stop = () => { ignoreKill.signal = 'SIGTERM'; diff --git a/runner/lib/tasks/testnet.js b/runner/lib/tasks/testnet.js index a984704..ffd9fbe 100644 --- a/runner/lib/tasks/testnet.js +++ b/runner/lib/tasks/testnet.js @@ -157,15 +157,17 @@ export const makeTasks = ({ } console.log('Fetching network config'); - // eslint-disable-next-line jsdoc/check-alignment - const { chainName, peers, rpcAddrs, seeds } = /** - * @type {{ - * chainName: string, - * peers: string[], - * rpcAddrs: string[], - * seeds: string[] - * } & Record} - */ (await fetchAsJSON(`${testnetOrigin}/network-config`)); + /** + * @typedef {object} NetworkConfigRequired + * @property {string} chainName + * @property {string[]} peers + * @property {string[]} rpcAddrs + * @property {string[]} seeds + */ + const { chainName, peers, rpcAddrs, seeds } = + /** @type {NetworkConfigRequired & Record} */ ( + await fetchAsJSON(`${testnetOrigin}/network-config`) + ); if (withMonitor !== false) { storageLocations.chainStorageLocation = chainStateDir; @@ -208,7 +210,9 @@ export const makeTasks = ({ const config = await TOML.parse.async( await fs.readFile(configPath, 'utf-8'), ); - const configP2p = /** @type {TOML.JsonMap} */ (config.p2p); + const configP2p = /** @type {import('@iarna/toml').JsonMap} */ ( + config.p2p + ); configP2p.persistent_peers = peers.join(','); configP2p.seeds = seeds.join(','); configP2p.addr_book_strict = false; @@ -496,7 +500,7 @@ ${chainName} chain does not yet know of address ${soloAddr} const processInfo = await getProcessInfo( /** @type {number} */ (chainCp.pid), - ); + ).catch(() => undefined); return harden({ stop, @@ -607,7 +611,7 @@ ${chainName} chain does not yet know of address ${soloAddr} const processInfo = await getProcessInfo( /** @type {number} */ (soloCp.pid), - ); + ).catch(() => undefined); const stop = () => { ignoreKill.signal = 'SIGTERM'; diff --git a/runner/lib/tasks/types.d.ts b/runner/lib/tasks/types.d.ts index 0e8799f..9627713 100644 --- a/runner/lib/tasks/types.d.ts +++ b/runner/lib/tasks/types.d.ts @@ -25,7 +25,9 @@ export type TaskResult = { export type RunKernelInfo = { readonly slogLines: AsyncIterable; - readonly processInfo: import('../helpers/process-info.js').ProcessInfo; + readonly processInfo: + | import('../helpers/process-info.js').ProcessInfo + | undefined; }; export type TaskEventStatus = Record & {