fix docker stream backpressure (#1445)
This commit is contained in:
1 parent
a485c8580b
commit
ca2cb80c3f
3 files changed
+87
-24
No files matched your search
@@ -14,6 +14,7 @@ import { Readable } from 'node:stream';
|
||||
import * as tls from 'node:tls';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { pumpWebStreamToWritable } from './stream-pump';
|
||||
import { toWebReadableStream } from './node-readable-stream';
|
||||
import { computeRequestTimeoutMs } from './backups/request-timeout';
|
||||
import { helperWaitDeadline } from './helper-wait-core';
|
||||
import type { Environment } from './db';
|
||||
@@ -467,14 +468,7 @@ export function httpsAgentRequest(
|
||||
}
|
||||
|
||||
if (streaming) {
|
||||
const readable = new ReadableStream({
|
||||
start(controller) {
|
||||
res.on('data', (chunk: Buffer) => controller.enqueue(new Uint8Array(chunk)));
|
||||
res.on('end', () => controller.close());
|
||||
res.on('error', (err) => controller.error(err));
|
||||
},
|
||||
cancel() { res.destroy(); }
|
||||
});
|
||||
const readable = toWebReadableStream(res);
|
||||
resolve(new Response(readable, { status, statusText, headers }));
|
||||
} else {
|
||||
const chunks: Buffer[] = [];
|
||||
@@ -792,22 +786,7 @@ export function unixSocketStreamRequest(
|
||||
}
|
||||
}
|
||||
|
||||
const readable = new ReadableStream({
|
||||
start(controller) {
|
||||
res.on('data', (chunk: Buffer) => {
|
||||
controller.enqueue(new Uint8Array(chunk));
|
||||
});
|
||||
res.on('end', () => {
|
||||
controller.close();
|
||||
});
|
||||
res.on('error', (err) => {
|
||||
controller.error(err);
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
res.destroy();
|
||||
}
|
||||
});
|
||||
const readable = toWebReadableStream(res);
|
||||
|
||||
resolve(new Response(readable, {
|
||||
status: res.statusCode || 200,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Readable } from 'node:stream';
|
||||
|
||||
/**
|
||||
* Convert a Node readable to a Web stream while preserving Node backpressure.
|
||||
* Cancellation and source errors are forwarded by Node's native adapter.
|
||||
*/
|
||||
export function toWebReadableStream(source: Readable): ReadableStream<Uint8Array> {
|
||||
return Readable.toWeb(source) as ReadableStream<Uint8Array>;
|
||||
}
|
||||
Reference in new issue
Block a user