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

feat: apps-engine timeout config #33690

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/two-guests-tan.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/weak-trees-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/apps-engine': minor
---

Add support to configure apps runtime timeout via the APPS_ENGINE_RUNTIME_TIMEOUT environment variable
5 changes: 0 additions & 5 deletions packages/apps-engine/src/server/ProxiedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ export class ProxiedApp {
public async call(method: `${AppMethod}`, ...args: Array<any>): Promise<any> {
let options;

// Pre events need to be fast as they block the user
if (method.startsWith('checkPre') || method.startsWith('executePre')) {
d-gubert marked this conversation as resolved.
Show resolved Hide resolved
options = { timeout: 1000 };
}

try {
return await this.appRuntime.sendRequest({ method: `app:${method}`, params: args }, options);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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);
}
Expand All @@ -78,7 +90,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
private readonly debug: debug.Debugger;

private readonly options = {
timeout: 10000,
timeout: getRuntimeTimeout(),
};

private readonly accessors: AppAccessorManager;
Expand Down
Loading