Skip to content

Commit 3950235

Browse files
committed
Flush stdout and stderr before the command exits so a reader of the pipe gets all of its output
1 parent 571eab1 commit 3950235

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/node.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,13 @@ export function main(argv: string[]) {
777777
}
778778
// Collecting first: node's exit teardown can deadlock while it frees very
779779
// large array buffers (seen on x64 CI runners with a few hundred MB left).
780-
Promise.resolve().then(() => runNode(o)).then((code) => (globalThis.gc?.(), process.exit(code)), (e) => {
780+
Promise.resolve().then(() => runNode(o)).then(async (code) => {
781+
globalThis.gc?.();
782+
// output a pipe has not taken yet goes out before the process does
783+
const flushed = [process.stdout, process.stderr].map((s) => new Promise<void>((done) => { s.write("", () => done()); }));
784+
await Promise.race([Promise.all(flushed), new Promise((done) => setTimeout(done, 10000).unref())]);
785+
process.exit(code);
786+
}, (e) => {
781787
console.error(`java-web: ${(e as Error).message}`);
782788
process.exit(1);
783789
});

0 commit comments

Comments
 (0)