diff --git a/src/shell.js b/src/shell.js index 0505de183..8ce344463 100644 --- a/src/shell.js +++ b/src/shell.js @@ -45,10 +45,10 @@ function spawn(tag, file, args, options) { const maxLines = options.maxLines || Number.MAX_SAFE_INTEGER; const logger = options.logger || null; - const signal = options.signal || null; // note: we use our own handler and not the child_process one + const abortSignal = options.abortSignal || null; // note: we use our own handler and not the child_process one return new Promise((resolve, reject) => { - const spawnOptions = _.omit(options, [ 'maxLines', 'logger', 'signal', 'onMessage', 'input', 'encoding' ]); + const spawnOptions = _.omit(options, [ 'maxLines', 'logger', 'abortSignal', 'onMessage', 'input', 'encoding' ]); const cp = child_process.spawn(file, args, spawnOptions); const stdoutBuffers = [], stderrBuffers = []; let stdoutLineCount = 0, stderrLineCount = 0; @@ -91,7 +91,7 @@ function spawn(tag, file, args, options) { debug(`${tag}: ${file} ${args.join(' ').replace(/\n/g, '\\n')} errored`, error); }); - signal?.addEventListener('abort', () => { + abortSignal?.addEventListener('abort', () => { debug(`${tag}: aborting ${cp.pid}`); child_process.execFile('/usr/bin/sudo', [ KILL_CHILD_CMD, cp.pid, process.pid ], { encoding: 'utf8' }, (error, stdout, stderr) => { if (error) debug(`${tag}: failed to kill children`, stdout, stderr); diff --git a/src/system.js b/src/system.js index dc7010bb6..de23c4d92 100644 --- a/src/system.js +++ b/src/system.js @@ -44,7 +44,7 @@ async function du(file, options) { assert.strictEqual(typeof file, 'string'); assert.strictEqual(typeof options, 'object'); - const [error, stdoutResult] = await safe(shell.sudo([ DU_CMD, file ], { encoding: 'utf8', signal: options.signal })); + const [error, stdoutResult] = await safe(shell.sudo([ DU_CMD, file ], { encoding: 'utf8', abortSignal: options.abortSignal })); if (error) throw new BoxError(BoxError.FS_ERROR, error); return parseInt(stdoutResult.trim(), 10); @@ -54,7 +54,7 @@ async function hdparm(file, options) { assert.strictEqual(typeof file, 'string'); assert.strictEqual(typeof options, 'object'); - const [error, stdoutResult] = await safe(shell.sudo([ HDPARM_CMD, file ], { encoding: 'utf8', signal: options.signal })); + const [error, stdoutResult] = await safe(shell.sudo([ HDPARM_CMD, file ], { encoding: 'utf8', abortSignal: options.abortSignal })); if (error) throw new BoxError(BoxError.FS_ERROR, error); const lines = stdoutResult.split('\n'); @@ -226,25 +226,25 @@ class FilesystemUsageTask extends AsyncTask { this.#filesystem = filesystem; } - async _run(signal) { + async _run(abortSignal) { const { filesystem, type, contents } = this.#filesystem; let percent = 5; if (type === 'ext4' || type === 'xfs') { // hdparm only works with block devices this.emitProgress(percent, 'Calculating Disk Speed'); - const [speedError, speed] = await safe(hdparm(filesystem, { signal })); + const [speedError, speed] = await safe(hdparm(filesystem, { abortSignal })); if (speedError) debug(`hdparm error ${filesystem}: ${speedError.message}`); this.emitData({ speed: speedError ? -1 : speed }); } else { this.emitData({ speed: -1 }); } - const dockerDf = await docker.df({ abortSignal: signal }); + const dockerDf = await docker.df({ abortSignal }); for (const content of contents) { percent += (90/contents.length+1); - if (signal.aborted) return; + if (abortSignal.aborted) return; this.emitProgress(percent,`Checking du of ${content.id} ${content.path}`); if (content.id === 'docker') { @@ -252,7 +252,7 @@ class FilesystemUsageTask extends AsyncTask { } else if (content.id === 'docker-volumes') { content.usage = dockerDf.Volumes.map((v) => v.UsageData.Size).reduce((a,b) => a + b, 0); } else { - const [error, usage] = await safe(du(content.path, { signal })); + const [error, usage] = await safe(du(content.path, { abortSignal })); if (error) debug(`du error ${content.path}: ${error.message}`); // can happen if app is installing etc content.usage = usage || 0; } diff --git a/src/tasks.js b/src/tasks.js index 9b5d470ec..368db34d8 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -179,9 +179,13 @@ async function startTask(id, options) { }, options.timeout); } - const sudoOptions = { preserveEnv: true, signal: ac.signal }; + const sudoArgs = [ START_TASK_CMD, id, logFile, options.nice || 0, options.memoryLimit || 400, options.oomScoreAdjust || 0 ]; + const sudoOptions = { + preserveEnv: true, + abortSignal: ac.signal, + }; - const [sudoError] = await safe(shell.sudo([ START_TASK_CMD, id, logFile, options.nice || 0, options.memoryLimit || 400, options.oomScoreAdjust || 0 ], sudoOptions)); + const [sudoError] = await safe(shell.sudo(sudoArgs, sudoOptions)); const code = sudoError ? sudoError.code : 0; debug(`startTask: ${id} completed with code ${code} ${!gTasks[id] ? '. this will be ignored' : ''}`);