From 3c6fac9ce45d6ea284bfee6855368533cbf60d55 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 20 Jan 2021 15:29:45 -0600 Subject: [PATCH] Wait for inner process to exit --- src/node/wrapper.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/node/wrapper.ts b/src/node/wrapper.ts index f6f84e2b..28803fe9 100644 --- a/src/node/wrapper.ts +++ b/src/node/wrapper.ts @@ -234,9 +234,7 @@ export class ParentProcess extends Process { this.logStdoutStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stdout.log"), opts) this.logStderrStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stderr.log"), opts) - this.onDispose(() => { - this.disposeChild() - }) + this.onDispose(() => this.disposeChild()) this.onChildMessage((message) => { switch (message.type) { @@ -252,11 +250,15 @@ export class ParentProcess extends Process { }) } - private disposeChild(): void { + private async disposeChild(): Promise { this.started = undefined if (this.child) { - this.child.removeAllListeners() - this.child.kill() + const child = this.child + child.removeAllListeners() + child.kill() + // Wait for the child to exit otherwise its output will be lost which can + // be especially problematic if you're trying to debug why cleanup failed. + await new Promise((r) => child!.on("exit", r)) } }