diff --git a/src/node/wrapper.ts b/src/node/wrapper.ts index f6f84e2bd..28803fe9c 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)) } }