Repository navigation
git-fcgi: add buffering proxy to quickly read from fcgi - #2
Merged
Merged
Conversation
shankerwangmiao
force-pushed
the
pr-bufferproxy
branch
from
March 16, 2026 16:17
6db1bcb to
f567739
Compare
shankerwangmiao
force-pushed
the
pr-bufferproxy
branch
from
March 16, 2026 16:32
f567739 to
4bf7569
Compare
shankerwangmiao
force-pushed
the
pr-bufferproxy
branch
from
March 16, 2026 16:46
4bf7569 to
4e7d180
Compare
shankerwangmiao
force-pushed
the
pr-bufferproxy
branch
from
March 16, 2026 17:02
4e7d180 to
6be0af8
Compare
with a buffer in memory or on a local storage, to prevent cgi processes from waiting for network IO.
shankerwangmiao
force-pushed
the
pr-bufferproxy
branch
from
March 16, 2026 17:21
6be0af8 to
27bdf9b
Compare
There was a problem hiding this comment.
Pull request overview
Adds a FastCGI buffering proxy in front of fcgiwrap to decouple upstream (CGI) response production from downstream network I/O, aiming to prevent CGI processes from blocking on slow client reads.
Changes:
- Introduce a new Go binary (
buffering-proxy) that proxies connections and buffers upstream→client data in memory and (optionally) on disk. - Update
cmd.shto run the buffering proxy on:5000and switchspawn-fcgito a Unix socket upstream (/tmp/fcgi.sock). - Update the Docker build to compile and ship the new
buffering-proxybinary.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| git-fcgi/cmd.sh | Starts buffering proxy and changes fcgiwrap to listen on a Unix socket instead of TCP port 5000. |
| git-fcgi/buffering-proxy.go | New buffering proxy implementation with CLI flags and disk spillover support. |
| git-fcgi/Dockerfile | Builds and copies the new buffering-proxy binary into the runtime image. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+220
to
+251
| } else { | ||
| tmpFile, err := os.CreateTemp(cfg.onDiskBufferPath, "buffer-*") | ||
| if err != nil { | ||
| fmt.Printf("Error creating temp file for disk buffer: %v\n", err) | ||
| close(channel) | ||
| upstreamConn.CloseRead() | ||
| break | ||
| } | ||
| err = os.Remove(tmpFile.Name()) | ||
| if err != nil { | ||
| fmt.Printf("Error removing temp file after creation: %v\n", err) | ||
| tmpFile.Close() | ||
| close(channel) | ||
| upstreamConn.CloseRead() | ||
| break | ||
| } | ||
| var n int64 | ||
| n, readErr = io.CopyN(tmpFile, upstreamConn, int64(cfg.onDiskBufferUnitSize)) | ||
| _, err = tmpFile.Seek(0, io.SeekStart) | ||
| if err != nil { | ||
| fmt.Printf("Error seeking to start of temp file: %v\n", err) | ||
| tmpFile.Close() | ||
| close(channel) | ||
| upstreamConn.CloseRead() | ||
| break | ||
| } | ||
| if n > 0 { | ||
| channel <- Buffer{diskBuf: tmpFile} | ||
| } else { | ||
| tmpFile.Close() | ||
| } | ||
| } |
Comment on lines
9
to
+18
| ( | ||
| while true; do | ||
| /go-queue --queue-size "${QUEUE_SIZE}" --port-number 8888 | ||
| done | ||
| )& | ||
| exec /usr/bin/spawn-fcgi -u www-data -g www-data -p 5000 -n -- /usr/bin/multiwatch -f ${THREADS} -- /usr/sbin/fcgiwrap | ||
| ( | ||
| while true; do | ||
| /buffering-proxy --listen ":5000" --max-buffer-size "${MAX_BUFFER_SIZE}" --on-disk-buffer-path "${BUFFER_PATH}" --upstream "unix:/tmp/fcgi.sock" | ||
| done | ||
| )& |
| /buffering-proxy --listen ":5000" --max-buffer-size "${MAX_BUFFER_SIZE}" --on-disk-buffer-path "${BUFFER_PATH}" --upstream "unix:/tmp/fcgi.sock" | ||
| done | ||
| )& | ||
| exec /usr/bin/spawn-fcgi -u www-data -g www-data -s /tmp/fcgi.sock -n -- /usr/bin/multiwatch -f "${THREADS}" -- /usr/sbin/fcgiwrap |
| value, err := strconv.ParseUint(val, 10, 64) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid number format: %v", err) | ||
| } |
Comment on lines
+79
to
+88
| fmt.Fprintln(os.Stderr, "invalid value for --buffer-unit-size: must be greater than zero") | ||
| os.Exit(2) | ||
| } | ||
| if onDiskBufferUnitSize == 0 { | ||
| fmt.Fprintln(os.Stderr, "invalid value for --on-disk-buffer-unit-size: must be greater than zero") | ||
| os.Exit(2) | ||
| } | ||
| if *maxResponseDeadline <= 0 { | ||
| fmt.Fprintln(os.Stderr, "invalid value for --max-deadline: must be greater than zero") | ||
| os.Exit(2) |
| } | ||
| upstreamConn, ok := _uc.(StreamConn) | ||
| if !ok { | ||
| fmt.Printf("Failed to cast upstream connection to TCPConn\n") |
Comment on lines
+154
to
+156
| go func() { //Downloading data from upstream to client, with buffering | ||
| channel := make(chan Buffer, int(cfg.maxBuffers)) | ||
| go func() { // Sender |
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.
with a buffer in memory or on a local storage, to prevent cgi processes from waiting for network IO.