Buffer request body to fix large push deadlock

This commit is contained in:
Chris Wanstrath 2026-03-01 22:12:57 -08:00
parent 360f4cedcf
commit 18c585e6a6

View File

@ -252,7 +252,7 @@ async function getDefaultBranch(bare: string): Promise<string> {
async function gitRpc(
repo: string,
service: string,
body: ReadableStream<Uint8Array> | null,
body: Uint8Array | ReadableStream<Uint8Array> | null,
): Promise<Response> {
const bare = repoPath(repo)
@ -594,7 +594,12 @@ app.on('POST', ['/:repo{.+\\.git}/git-receive-pack', '/:repo/git-receive-pack'],
await ensureBareRepo(repoParam)
const response = await gitRpc(repoParam, 'git-receive-pack', c.req.raw.body)
// Buffer the request body before passing to git-receive-pack. Piping a live
// HTTP ReadableStream directly to subprocess stdin deadlocks on large pushes:
// the pipe buffer fills, stalling the stream reader, while git-receive-pack
// can't finish reading stdin to produce stdout — both sides block.
const body = new Uint8Array(await c.req.raw.arrayBuffer())
const response = await gitRpc(repoParam, 'git-receive-pack', body)
// Buffer the full response so we can inject sideband error messages before the
// final flush-pkt on deploy failure. The receive-pack response is just ref status
// lines (not pack data), so the buffer is small regardless of push size.