Skip to content

Commit

Permalink
Force script to time out
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Jun 26, 2018
1 parent 73cd594 commit d8bbe04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rocketchat-integrations/server/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const Api = new Restivus({
const compiledScripts = {};
function buildSandbox(store = {}) {
const sandbox = {
scriptTimeout(reject) {
return setTimeout(() => reject('timed out'), 3000);
},
_,
s,
console,
Expand Down Expand Up @@ -243,13 +246,14 @@ function executeIntegrationRest() {
const result = Future.fromPromise(vm.runInNewContext(`
new Promise((resolve, reject) => {
Fiber(() => {
scriptTimeout(reject);
try {
resolve(script.process_incoming_request({ request: request }));
} catch(e) {
reject(e);
}
}).run();
}).catch((error) => console.error(error));
}).catch((error) => { throw new Error(error); });
`, sandbox, {
timeout: 3000
})).wait();
Expand Down

0 comments on commit d8bbe04

Please sign in to comment.