fix(rpc): respect stdout backpressure

closes #4897
This commit is contained in:
Armin Ronacher
2026-05-24 11:28:02 +02:00
parent fc51a40d02
commit d0d1d8edca
6 changed files with 134 additions and 80 deletions

View File

@@ -1,3 +1,5 @@
import { once } from "node:events";
interface StdoutTakeoverState {
rawStdoutWrite: (chunk: string, callback?: (error?: Error | null) => void) => boolean;
rawStderrWrite: (chunk: string, callback?: (error?: Error | null) => void) => boolean;
@@ -46,12 +48,11 @@ export function isStdoutTakenOver(): boolean {
return stdoutTakeoverState !== undefined;
}
export function writeRawStdout(text: string): void {
if (stdoutTakeoverState) {
stdoutTakeoverState.rawStdoutWrite(text);
return;
export async function writeRawStdout(text: string): Promise<void> {
const canContinue = stdoutTakeoverState ? stdoutTakeoverState.rawStdoutWrite(text) : process.stdout.write(text);
if (!canContinue) {
await once(process.stdout, "drain");
}
process.stdout.write(text);
}
export async function flushRawStdout(): Promise<void> {