Skip to content

Commit 3c6fac9

Browse files
committed
Wait for inner process to exit
1 parent 055e0ef commit 3c6fac9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/node/wrapper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ export class ParentProcess extends Process {
234234
this.logStdoutStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stdout.log"), opts)
235235
this.logStderrStream = rfs.createStream(path.join(paths.data, "coder-logs", "code-server-stderr.log"), opts)
236236

237-
this.onDispose(() => {
238-
this.disposeChild()
239-
})
237+
this.onDispose(() => this.disposeChild())
240238

241239
this.onChildMessage((message) => {
242240
switch (message.type) {
@@ -252,11 +250,15 @@ export class ParentProcess extends Process {
252250
})
253251
}
254252

255-
private disposeChild(): void {
253+
private async disposeChild(): Promise<void> {
256254
this.started = undefined
257255
if (this.child) {
258-
this.child.removeAllListeners()
259-
this.child.kill()
256+
const child = this.child
257+
child.removeAllListeners()
258+
child.kill()
259+
// Wait for the child to exit otherwise its output will be lost which can
260+
// be especially problematic if you're trying to debug why cleanup failed.
261+
await new Promise((r) => child!.on("exit", r))
260262
}
261263
}
262264

0 commit comments

Comments
 (0)