Skip to content

Commit

Permalink
fix: deno runtime controller not handling undefined child process ref…
Browse files Browse the repository at this point in the history
…erence correctly (#33494)
  • Loading branch information
d-gubert authored Oct 9, 2024
1 parent d9fe5bb commit 5f9826b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-bugs-cry.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -166,6 +166,11 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
}

public async killProcess(): Promise<void> {
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');
Expand Down Expand Up @@ -201,7 +206,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter {

public async getStatus(): Promise<AppStatus> {
// 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;
}

Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 5f9826b

Please sign in to comment.