Skip to content

Commit 9cf9183

Browse files
authored
Turbopack: flush Node.js worker IPC on error (#84077)
If the Nodejs process exited too quickly after `sendError`, Turbopack never received the error message and then previously crashed with panics such as ``` - Execution of PostCssTransformedAsset::process failed - creating new process - reading packet length - unexpected end of file ``` Now, flush the socket before calling `process.exit()`
1 parent 237f142 commit 9cf9183

File tree

1 file changed

+6
-4
lines changed
  • turbopack/crates/turbopack-node/js/src/ipc

1 file changed

+6
-4
lines changed

turbopack/crates/turbopack-node/js/src/ipc/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,20 @@ function createIpc<TIncoming, TOutgoing>(
169169
sendReady,
170170

171171
async sendError(error: Error): Promise<never> {
172+
let failed = false
172173
try {
173174
await send({
174175
type: 'error',
175176
...structuredError(error),
176177
})
177178
} catch (err) {
179+
// There's nothing we can do about errors that happen after this point, we can't tell anyone
180+
// about them.
178181
console.error('failed to send error back to rust:', err)
179-
// ignore and exit anyway
180-
process.exit(1)
182+
failed = true
181183
}
182-
183-
process.exit(0)
184+
await new Promise<void>((res) => socket.end(() => res()))
185+
process.exit(failed ? 1 : 0)
184186
},
185187
}
186188
}

0 commit comments

Comments
 (0)