From 5c9c38b4e639a6689322e7afd5040e41bfb823b9 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Wed, 4 Dec 2024 10:14:27 -0300 Subject: [PATCH] apps-engine timeout config https://github.com/RocketChat/Rocket.Chat/pull/33690 --- src/server/ProxiedApp.ts | 6 +++--- src/server/runtime/deno/AppsEngineDenoRuntime.ts | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/server/ProxiedApp.ts b/src/server/ProxiedApp.ts index adc98e26c..1af91b3ce 100644 --- a/src/server/ProxiedApp.ts +++ b/src/server/ProxiedApp.ts @@ -54,9 +54,9 @@ export class ProxiedApp { let options; // Pre events need to be fast as they block the user - if (method.startsWith('checkPre') || method.startsWith('executePre')) { - options = { timeout: 1000 }; - } + // if (method.startsWith('checkPre') || method.startsWith('executePre')) { + // options = { timeout: 1000 }; + // } try { return await this.appRuntime.sendRequest({ method: `app:${method}`, params: args }, options); diff --git a/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 15a74d29e..6f9e55ae3 100644 --- a/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -53,6 +53,18 @@ const COMMAND_PONG = '_zPONG'; export const JSONRPC_METHOD_NOT_FOUND = -32601; +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 defaultTimeout; + } + + return envValue; +} + export function isValidOrigin(accessor: string): accessor is typeof ALLOWED_ACCESSOR_METHODS[number] { return ALLOWED_ACCESSOR_METHODS.includes(accessor as any); } @@ -88,7 +100,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { private readonly debug: debug.Debugger; private readonly options = { - timeout: 10000, + timeout: getRuntimeTimeout(), }; private readonly accessors: AppAccessorManager;