diff --git a/.changeset/proud-bugs-cry.md b/.changeset/proud-bugs-cry.md new file mode 100644 index 000000000000..854f9c6372fd --- /dev/null +++ b/.changeset/proud-bugs-cry.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/apps-engine': patch +--- + +Fixed a problem in the deno runtime controller where it would not handle undefined child process references correctly diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 8d589c0d2e9e..5eb3b7cd0918 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -71,7 +71,7 @@ export type DenoRuntimeOptions = { }; export class DenoRuntimeSubprocessController extends EventEmitter { - private deno: child_process.ChildProcess; + private deno: child_process.ChildProcess | undefined; private state: 'uninitialized' | 'ready' | 'invalid' | 'restarting' | 'unknown' | 'stopped'; @@ -166,6 +166,11 @@ export class DenoRuntimeSubprocessController extends EventEmitter { } public async killProcess(): Promise { + if (!this.deno) { + this.debug('No child process reference'); + return; + } + // This field is not populated if the process is killed by the OS if (this.deno.killed) { this.debug('App process was already killed'); @@ -201,7 +206,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter { public async getStatus(): Promise { // If the process has been terminated, we can't get the status - if (this.deno.exitCode !== null) { + if (!this.deno || this.deno.exitCode !== null) { return AppStatus.UNKNOWN; } @@ -311,6 +316,10 @@ export class DenoRuntimeSubprocessController extends EventEmitter { } private setupListeners(): void { + if (!this.deno) { + return; + } + this.deno.stderr.on('data', this.parseError.bind(this)); this.deno.on('error', (err) => { this.state = 'invalid';