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

Cap execution timeout at 5 minutes #509

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
master:
new features:
- GH-509 Added a limit to the maximum allowed script execution timeout

3.5.1:
date: 2019-11-13
chores:
Expand Down
11 changes: 9 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var _ = require('lodash'),
teleportJS = require('teleport-javascript'),
bootcode = require('./bootcode'),

MAX_EXECUTION_TIMEOUT = 5 * 60 * 1000, // 5 minutes
TO_WAITBUFFER = 500, // time to wait for sandbox to delcare timeout
EXECUTION_TIMEOUT_ERROR_MESSAGE = 'sandbox not responding',
BRIDGE_DISCONNECTING_ERROR_MESSAGE = 'sandbox: execution interrupted, bridge disconnecting.',
Expand All @@ -17,8 +18,14 @@ PostmanSandbox = function PostmanSandbox (options, callback) {
this.executing = {};
this.debug = Boolean(options.debug);

// set the dispatch timeout of UVM based on what is set in options unless original options sends the same
_.isFinite(options.timeout) && (options.dispatchTimeout = this.executionTimeout = options.timeout);
if (_.isFinite(options.timeout)) {
// cap timeout value to the allowed maximum timeout
options.timeout > MAX_EXECUTION_TIMEOUT && (options.timeout = MAX_EXECUTION_TIMEOUT);

// set the dispatch timeout of UVM based on what is set in options
// unless original options sends the same
options.dispatchTimeout = this.executionTimeout = options.timeout;
}

UniversalVM.call(this, options, function (err, context) {
if (err) { return callback(err); }
Expand Down
10 changes: 10 additions & 0 deletions test/unit/sandbox-timeout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
});
});

it('should not allow setting timeout more that a limit', function (done) {
Sandbox.createContext({
timeout: 10 * 60 * 1000 // 10 minutes
}, function (err, ctx) {
expect(err).to.not.exist;
expect(ctx.executionTimeout).to.equal(5 * 60 * 1000); // 5 minutes
done();
});
});

it('should clear timeout on bridge disconnect', function (done) {
Sandbox.createContext({
debug: true,
Expand Down