Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): handle missing procfs #91

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions runner/lib/helpers/procsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const makeProcfsHelper = ({ fs, spawn, startPid = process.pid }) => {

return parseInt(res.toString(bufferOptions.encoding), 10);
})();
userHertzP.catch(() => {});

/** @typedef {string[]} ProcStat */
/**
Expand Down Expand Up @@ -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<string, ProcessInfo>} */
Expand Down
40 changes: 22 additions & 18 deletions runner/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ const main = async (progName, rawArgs, powers) => {
/** @type {Promise<void>[]} */
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;

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -616,7 +620,7 @@ const main = async (progName, rawArgs, powers) => {
async () =>
aggregateTryFinally(
async () => {
chainMonitor.stop();
chainMonitor?.stop();

if (!chainExited) {
stageConsole.log('Stopping chain');
Expand Down
10 changes: 7 additions & 3 deletions runner/lib/monitor/loadgen-monitor.js
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions runner/lib/tasks/local-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const makeTasks = ({

const processInfo = await getProcessInfo(
/** @type {number} */ (chainCp.pid),
);
).catch(() => undefined);

return harden({
stop,
Expand Down Expand Up @@ -576,7 +576,7 @@ export const makeTasks = ({

const processInfo = await getProcessInfo(
/** @type {number} */ (soloCp.pid),
);
).catch(() => undefined);

const stop = () => {
ignoreKill.signal = 'SIGTERM';
Expand Down
28 changes: 16 additions & 12 deletions runner/lib/tasks/testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>}
*/ (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<string, unknown>} */ (
await fetchAsJSON(`${testnetOrigin}/network-config`)
);

if (withMonitor !== false) {
storageLocations.chainStorageLocation = chainStateDir;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion runner/lib/tasks/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export type TaskResult = {

export type RunKernelInfo = {
readonly slogLines: AsyncIterable<Buffer>;
readonly processInfo: import('../helpers/process-info.js').ProcessInfo;
readonly processInfo:
| import('../helpers/process-info.js').ProcessInfo
| undefined;
};

export type TaskEventStatus = Record<string, unknown> & {
Expand Down