mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(proxy): honor backpressure in cliproxy local streaming (#1379)
This commit is contained in:
@@ -116,9 +116,22 @@ export function createCliproxyLocalProxyRouter(deps: CliproxyLocalProxyDeps = {}
|
||||
}
|
||||
|
||||
res.writeHead(proxyStatus, proxyRes.headers);
|
||||
// Manual streaming instead of pipe() for Bun runtime compatibility
|
||||
proxyRes.on('data', (chunk: Buffer) => res.write(chunk));
|
||||
proxyRes.on('end', () => res.end());
|
||||
// Manual streaming instead of pipe() for Bun runtime compatibility.
|
||||
// Explicitly honor downstream backpressure to avoid unbounded buffering.
|
||||
const onDrain = () => proxyRes.resume();
|
||||
|
||||
proxyRes.on('data', (chunk: Buffer) => {
|
||||
const canContinue = res.write(chunk);
|
||||
if (!canContinue) {
|
||||
proxyRes.pause();
|
||||
res.once('drain', onDrain);
|
||||
}
|
||||
});
|
||||
|
||||
proxyRes.on('end', () => {
|
||||
res.off('drain', onDrain);
|
||||
res.end();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user