From 6a0ae8c2f4f9c429cf2bd3803dd36032e872d9a5 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Oct 2024 13:42:30 -0300 Subject: [PATCH 1/5] Add a new environment variable to control apps-engine runtime timeout --- .../server/runtime/deno/AppsEngineDenoRuntime.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 5eb3b7cd0918..be6117b6e2bd 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -52,6 +52,17 @@ const COMMAND_PONG = '_zPONG'; export const JSONRPC_METHOD_NOT_FOUND = -32601; +export function getDefaultRuntimeTimeout() { + const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : 10000; + + if (envValue < 0) { + console.log('Environment variable APPS_ENGINE_RUNTIME_TIMEOUT has a negative value, ignoring...'); + return 10000; + } + + return envValue; +} + export function isValidOrigin(accessor: string): accessor is (typeof ALLOWED_ACCESSOR_METHODS)[number] { return ALLOWED_ACCESSOR_METHODS.includes(accessor as any); } @@ -78,7 +89,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { private readonly debug: debug.Debugger; private readonly options = { - timeout: 10000, + timeout: getDefaultRuntimeTimeout(), }; private readonly accessors: AppAccessorManager; From ec4f57e2ca7a214f6ffad48340ce9a5513e6015f Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Oct 2024 13:45:04 -0300 Subject: [PATCH 2/5] Remove rule that shortened timeouts for `Pre` app events --- packages/apps-engine/src/server/ProxiedApp.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/apps-engine/src/server/ProxiedApp.ts b/packages/apps-engine/src/server/ProxiedApp.ts index e2605c8375de..ebe2cf04d8fc 100644 --- a/packages/apps-engine/src/server/ProxiedApp.ts +++ b/packages/apps-engine/src/server/ProxiedApp.ts @@ -53,11 +53,6 @@ export class ProxiedApp { public async call(method: `${AppMethod}`, ...args: Array): Promise { let options; - // Pre events need to be fast as they block the user - if (method.startsWith('checkPre') || method.startsWith('executePre')) { - options = { timeout: 1000 }; - } - try { return await this.appRuntime.sendRequest({ method: `app:${method}`, params: args }, options); } catch (e) { From c51b6780ba76482affed61ba9519c8f9e2090506 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Oct 2024 13:57:59 -0300 Subject: [PATCH 3/5] Add changesets --- .changeset/two-guests-tan.md | 5 +++++ .changeset/weak-trees-exercise.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/two-guests-tan.md create mode 100644 .changeset/weak-trees-exercise.md diff --git a/.changeset/two-guests-tan.md b/.changeset/two-guests-tan.md new file mode 100644 index 000000000000..ff44f0ef493b --- /dev/null +++ b/.changeset/two-guests-tan.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/apps-engine': patch +--- + +Removed the 1 second timeout of `Pre` app events. Now they will follow the "global" configuration diff --git a/.changeset/weak-trees-exercise.md b/.changeset/weak-trees-exercise.md new file mode 100644 index 000000000000..230c087ccd83 --- /dev/null +++ b/.changeset/weak-trees-exercise.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/apps-engine': minor +--- + +Add support to configure apps runtime timeout via the APPS_ENGINE_RUNTIME_TIMEOUT environment variable From b3f0fa5a4b7913dd21983ed6abcf751215ccb7bf Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Oct 2024 16:08:07 -0300 Subject: [PATCH 4/5] Increase default runtime timeout to 30s --- .../src/server/runtime/deno/AppsEngineDenoRuntime.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index be6117b6e2bd..68d976a67f17 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -53,11 +53,11 @@ const COMMAND_PONG = '_zPONG'; export const JSONRPC_METHOD_NOT_FOUND = -32601; export function getDefaultRuntimeTimeout() { - const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : 10000; + const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : 30000; if (envValue < 0) { console.log('Environment variable APPS_ENGINE_RUNTIME_TIMEOUT has a negative value, ignoring...'); - return 10000; + return 30000; } return envValue; From 6703cbc11b1e0570056e3657b986206aa97e12d9 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Oct 2024 16:17:24 -0300 Subject: [PATCH 5/5] Small refactor --- .../src/server/runtime/deno/AppsEngineDenoRuntime.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 68d976a67f17..a5dc65897b35 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -52,12 +52,13 @@ const COMMAND_PONG = '_zPONG'; export const JSONRPC_METHOD_NOT_FOUND = -32601; -export function getDefaultRuntimeTimeout() { - const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : 30000; +export function getRuntimeTimeout() { + const defaultTimeout = 30000; + const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : defaultTimeout; if (envValue < 0) { console.log('Environment variable APPS_ENGINE_RUNTIME_TIMEOUT has a negative value, ignoring...'); - return 30000; + return defaultTimeout; } return envValue; @@ -89,7 +90,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { private readonly debug: debug.Debugger; private readonly options = { - timeout: getDefaultRuntimeTimeout(), + timeout: getRuntimeTimeout(), }; private readonly accessors: AppAccessorManager;