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

[FIX] The process was freezing in some cases when HTTP calls exceeds timeout on integrations #11253

Merged
merged 4 commits into from
Jun 26, 2018
Merged
Changes from 2 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
18 changes: 16 additions & 2 deletions packages/rocketchat-integrations/server/api/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* globals Meteor Restivus logger processWebhookMessage*/
// TODO: remove globals

import Fiber from 'fibers';
import Future from 'fibers/future';
import _ from 'underscore';
import s from 'underscore.string';
import vm from 'vm';
Expand Down Expand Up @@ -64,6 +66,8 @@ function buildSandbox(store = {}) {
s,
console,
moment,
Fiber,
Promise,
Livechat: RocketChat.Livechat,
Store: {
set(key, val) {
Expand Down Expand Up @@ -236,9 +240,19 @@ function executeIntegrationRest() {
sandbox.script = script;
sandbox.request = request;

const result = vm.runInNewContext('script.process_incoming_request({ request: request })', sandbox, {
const result = Future.fromPromise(vm.runInNewContext(`
new Promise((resolve, reject) => {
Copy link
Member

@sampaiodiego sampaiodiego Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, add a catch to this Promise, otherwise calling reject will thrown a unhandled promise rejection

edit: I've added 👍

Fiber(() => {
try {
resolve(script.process_incoming_request({ request: request }));
} catch(e) {
reject(e);
}
}).run();
});
`, sandbox, {
timeout: 3000
});
})).wait();

if (!result) {
logger.incoming.debug('[Process Incoming Request result of Trigger', this.integration.name, ':] No data');
Expand Down