diff --git a/src/mounts.js b/src/mounts.js index 25be721e8..dfa295d1b 100644 --- a/src/mounts.js +++ b/src/mounts.js @@ -152,7 +152,8 @@ async function getStatus(mountType, hostPath) { if (mountType === 'filesystem') return { state: 'active', message: 'Mounted' }; - const state = safe.child_process.execSync(`mountpoint -q -- ${hostPath}`) ? 'active' : 'inactive'; + const [error] = await safe(shell.exec(`mountpoint -q -- ${hostPath}`, { timeout: 5000 })); + const state = error ? 'inactive' : 'active'; if (mountType === 'mountpoint') return { state, message: state === 'active' ? 'Mounted' : 'Not mounted' }; diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index ebc24bd2e..9ca3dc63b 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -257,7 +257,8 @@ async function testConfig(apiConfig) { } if (apiConfig.provider === PROVIDER_MOUNTPOINT) { - if (!safe.child_process.execSync(`mountpoint -q -- ${apiConfig.mountPoint}`)) throw new BoxError(BoxError.BAD_FIELD, `${apiConfig.mountPoint} is not mounted`); + const [error] = await safe(shell.exec(`mountpoint -q -- ${apiConfig.mountPoint}`, { timeout: 5000 })); + if (error) throw new BoxError(BoxError.BAD_FIELD, `${apiConfig.mountPoint} is not mounted: ${error.message}`); } const rootPath = apiConfig.rootPath; diff --git a/src/test/shell-test.js b/src/test/shell-test.js index 8fdeb56ae..e84dd80ce 100644 --- a/src/test/shell-test.js +++ b/src/test/shell-test.js @@ -52,27 +52,32 @@ describe('shell', function () { await safe(shell.promises.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {})); }); - it('execSync a valid shell program', function (done) { + it('exec a valid shell program', function (done) { shell.exec('test', 'ls -l | wc -c', {}, function (error) { done(error); }); }); - it('execSync a valid shell program (promises)', async function () { + it('exec a valid shell program (promises)', async function () { await shell.promises.exec('test', 'ls -l | wc -c', {}); }); - it('execSync throws for invalid program', function (done) { + it('exec throws for invalid program', function (done) { shell.exec('test', 'cannotexist', {}, function (error) { expect(error).to.be.ok(); done(); }); }); - it('execSync throws for failed program', function (done) { + it('exec throws for failed program', function (done) { shell.exec('test', 'false', {}, function (error) { expect(error).to.be.ok(); done(); }); }); + + it('exec times out properly', async function () { + const [error] = await safe(shell.promises.exec('sleeping', 'sleep 20', { timeout: 1000 })); + expect(error.signal).to.be('SIGTERM'); // somtimes code is ETIMEOUT + }); });