file: use buffered pipes to prevent deadlock during pack negotiation#1826
Open
lukemarsden wants to merge 1 commit intogo-git:mainfrom
Open
file: use buffered pipes to prevent deadlock during pack negotiation#1826lukemarsden wants to merge 1 commit intogo-git:mainfrom
lukemarsden wants to merge 1 commit intogo-git:mainfrom
Conversation
f1fdd57 to
a9b5c72
Compare
The file transport uses in-process pipes to communicate between client and server. With unbuffered io.Pipe, both sides can deadlock when cloning repositories with many refs (e.g., 300+ branches). The deadlock occurs because: 1. Client writes "have" lines to stdin pipe 2. Server writes advertised refs and ACKs to stdout pipe 3. Both pipes fill up (io.Pipe has zero buffer) 4. Both sides block waiting for the other to read This commit introduces a buffered pipe implementation that allows writes to proceed up to a configurable limit (10MB) before blocking. If the buffer is exceeded, an error is returned rather than deadlocking. The 10MB limit is far more than needed for pack negotiation - even with 1000 refs, the data is typically under 100KB.
a9b5c72 to
b982028
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The file transport uses in-process pipes to communicate between client and server. With unbuffered
io.Pipe, both sides can deadlock when cloning repositories with many refs (e.g., 300+ branches).The deadlock occurs because:
io.Pipehas zero buffer)Solution
This PR introduces a buffered pipe implementation that allows writes to proceed up to a configurable limit (10MB) before returning an error. If the buffer is exceeded,
ErrBufferFullis returned rather than deadlocking indefinitely.The 10MB limit is far more than needed for pack negotiation - even with 1000 refs, the data is typically under 100KB.
Changes
buffered_pipe.go: New buffered pipe implementation with configurable max sizeclient.go: Use buffered pipes for stdin and stdout instead ofio.Pipebuffered_pipe_test.go: Tests for the buffered pipe implementationTesting
All existing file transport tests pass:
New tests added for the buffered pipe: