swh:1:snp:87728f882295b5ba27035837248a04c5be121c53
Revision 6bc0cb5176a5e42ca4a74e3558e8f0790ed09bb1 authored by Jeff King on 20 May 2015, 07:37:09 UTC, committed by Junio C Hamano on 26 May 2015, 03:43:18 UTC
When http-backend spawns "upload-pack" to do ref
negotiation, it streams the http request body to
upload-pack, who then streams the http response back to the
client as it reads. In theory, git can go full-duplex; the
client can consume our response while it is still sending
the request.  In practice, however, HTTP is a half-duplex
protocol. Even if our client is ready to read and write
simultaneously, we may have other HTTP infrastructure in the
way, including the webserver that spawns our CGI, or any
intermediate proxies.

In at least one documented case[1], this leads to deadlock
when trying a fetch over http. What happens is basically:

  1. Apache proxies the request to the CGI, http-backend.

  2. http-backend gzip-inflates the data and sends
     the result to upload-pack.

  3. upload-pack acts on the data and generates output over
     the pipe back to Apache. Apache isn't reading because
     it's busy writing (step 1).

This works fine most of the time, because the upload-pack
output ends up in a system pipe buffer, and Apache reads
it as soon as it finishes writing. But if both the request
and the response exceed the system pipe buffer size, then we
deadlock (Apache blocks writing to http-backend,
http-backend blocks writing to upload-pack, and upload-pack
blocks writing to Apache).

We need to break the deadlock by spooling either the input
or the output. In this case, it's ideal to spool the input,
because Apache does not start reading either stdout _or_
stderr until we have consumed all of the input. So until we
do so, we cannot even get an error message out to the
client.

The solution is fairly straight-forward: we read the request
body into an in-memory buffer in http-backend, freeing up
Apache, and then feed the data ourselves to upload-pack. But
there are a few important things to note:

  1. We limit the in-memory buffer to prevent an obvious
     denial-of-service attack. This is a new hard limit on
     requests, but it's unlikely to come into play. The
     default value is 10MB, which covers even the ridiculous
     100,000-ref negotation in the included test (that
     actually caps out just over 5MB). But it's configurable
     on the off chance that you don't mind spending some
     extra memory to make even ridiculous requests work.

  2. We must take care only to buffer when we have to. For
     pushes, the incoming packfile may be of arbitrary
     size, and we should connect the input directly to
     receive-pack. There's no deadlock problem here, though,
     because we do not produce any output until the whole
     packfile has been read.

     For upload-pack's initial ref advertisement, we
     similarly do not need to buffer. Even though we may
     generate a lot of output, there is no request body at
     all (i.e., it is a GET, not a POST).

[1] http://article.gmane.org/gmane.comp.version-control.git/269020

Test-adapted-from: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cc969c8
History
Tip revision: 6c40894d2466d4e7fddc047a05116aa9d14712ee authored by Junio C Hamano on 30 August 2021, 23:06:22 UTC
The second batch
Tip revision: 6c40894
File Mode Size
Documentation
block-sha1
builtin
compat
contrib
ewah
git-gui
gitk-git
gitweb
mergetools
perl
po
ppc
t
templates
vcs-svn
xdiff
.gitattributes -rw-r--r-- 105 bytes
.gitignore -rw-r--r-- 3.6 KB
.mailmap -rw-r--r-- 13.9 KB
COPYING -rw-r--r-- 18.3 KB
GIT-VERSION-GEN -rwxr-xr-x 764 bytes
INSTALL -rw-r--r-- 8.8 KB
LGPL-2.1 -rw-r--r-- 26.2 KB
Makefile -rw-r--r-- 72.0 KB
README -rw-r--r-- 2.6 KB
RelNotes l--------- 32 bytes
abspath.c -rw-r--r-- 4.4 KB
aclocal.m4 -rw-r--r-- 1.4 KB
advice.c -rw-r--r-- 3.2 KB
advice.h -rw-r--r-- 927 bytes
alias.c -rw-r--r-- 1.5 KB
alloc.c -rw-r--r-- 2.6 KB
archive-tar.c -rw-r--r-- 11.0 KB
archive-zip.c -rw-r--r-- 12.1 KB
archive.c -rw-r--r-- 14.4 KB
archive.h -rw-r--r-- 1.3 KB
argv-array.c -rw-r--r-- 1.4 KB
argv-array.h -rw-r--r-- 577 bytes
attr.c -rw-r--r-- 19.0 KB
attr.h -rw-r--r-- 1.6 KB
base85.c -rw-r--r-- 2.8 KB
bisect.c -rw-r--r-- 23.6 KB
bisect.h -rw-r--r-- 644 bytes
blob.c -rw-r--r-- 389 bytes
blob.h -rw-r--r-- 664 bytes
branch.c -rw-r--r-- 7.9 KB
branch.h -rw-r--r-- 1.9 KB
builtin.h -rw-r--r-- 8.7 KB
bulk-checkin.c -rw-r--r-- 7.1 KB
bulk-checkin.h -rw-r--r-- 323 bytes
bundle.c -rw-r--r-- 11.8 KB
bundle.h -rw-r--r-- 707 bytes
cache-tree.c -rw-r--r-- 16.9 KB
cache-tree.h -rw-r--r-- 1.5 KB
cache.h -rw-r--r-- 57.8 KB
check-builtins.sh -rwxr-xr-x 590 bytes
check-racy.c -rw-r--r-- 538 bytes
check_bindir -rwxr-xr-x 374 bytes
color.c -rw-r--r-- 5.2 KB
color.h -rw-r--r-- 3.1 KB
column.c -rw-r--r-- 9.8 KB
column.h -rw-r--r-- 1.4 KB
combine-diff.c -rw-r--r-- 40.2 KB
command-list.txt -rw-r--r-- 8.0 KB
commit-slab.h -rw-r--r-- 4.0 KB
commit.c -rw-r--r-- 39.3 KB
commit.h -rw-r--r-- 12.7 KB
config.c -rw-r--r-- 54.7 KB
config.mak.in -rw-r--r-- 540 bytes
config.mak.uname -rw-r--r-- 15.6 KB
configure.ac -rw-r--r-- 32.0 KB
connect.c -rw-r--r-- 17.5 KB
connect.h -rw-r--r-- 596 bytes
connected.c -rw-r--r-- 3.2 KB
connected.h -rw-r--r-- 930 bytes
convert.c -rw-r--r-- 30.2 KB
convert.h -rw-r--r-- 2.3 KB
copy.c -rw-r--r-- 1.2 KB
credential-cache--daemon.c -rw-r--r-- 6.3 KB
credential-cache.c -rw-r--r-- 2.9 KB
credential-store.c -rw-r--r-- 4.0 KB
credential.c -rw-r--r-- 7.6 KB
credential.h -rw-r--r-- 822 bytes
csum-file.c -rw-r--r-- 4.1 KB
csum-file.h -rw-r--r-- 1.1 KB
ctype.c -rw-r--r-- 2.6 KB
daemon.c -rw-r--r-- 29.6 KB
date.c -rw-r--r-- 25.8 KB
decorate.c -rw-r--r-- 1.8 KB
decorate.h -rw-r--r-- 400 bytes
delta.h -rw-r--r-- 3.4 KB
diff-delta.c -rw-r--r-- 15.4 KB
diff-lib.c -rw-r--r-- 14.0 KB
diff-no-index.c -rw-r--r-- 5.5 KB
diff.c -rw-r--r-- 135.3 KB
diff.h -rw-r--r-- 11.5 KB
diffcore-break.c -rw-r--r-- 8.8 KB
diffcore-delta.c -rw-r--r-- 5.4 KB
diffcore-order.c -rw-r--r-- 2.4 KB
diffcore-pickaxe.c -rw-r--r-- 5.7 KB
diffcore-rename.c -rw-r--r-- 17.3 KB
diffcore.h -rw-r--r-- 4.8 KB
dir.c -rw-r--r-- 41.6 KB
dir.h -rw-r--r-- 6.9 KB
editor.c -rw-r--r-- 1.5 KB
entry.c -rw-r--r-- 7.4 KB
environment.c -rw-r--r-- 7.7 KB
exec_cmd.c -rw-r--r-- 3.2 KB
exec_cmd.h -rw-r--r-- 509 bytes
fast-import.c -rw-r--r-- 87.3 KB
fetch-pack.c -rw-r--r-- 25.7 KB
fetch-pack.h -rw-r--r-- 1.0 KB
fmt-merge-msg.h -rw-r--r-- 187 bytes
fsck.c -rw-r--r-- 13.4 KB
fsck.h -rw-r--r-- 1.1 KB
generate-cmdlist.sh -rwxr-xr-x 433 bytes
gettext.c -rw-r--r-- 4.3 KB
gettext.h -rw-r--r-- 1.4 KB
git-add--interactive.perl -rwxr-xr-x 36.0 KB
git-am.sh -rwxr-xr-x 22.7 KB
git-archimport.perl -rwxr-xr-x 36.0 KB
git-bisect.sh -rwxr-xr-x 11.7 KB
git-compat-util.h -rw-r--r-- 20.7 KB
git-cvsexportcommit.perl -rwxr-xr-x 12.6 KB
git-cvsimport.perl -rwxr-xr-x 31.3 KB
git-cvsserver.perl -rwxr-xr-x 158.6 KB
git-difftool--helper.sh -rwxr-xr-x 2.0 KB
git-difftool.perl -rwxr-xr-x 13.2 KB
git-filter-branch.sh -rwxr-xr-x 11.5 KB
git-instaweb.sh -rwxr-xr-x 18.1 KB
git-merge-octopus.sh -rwxr-xr-x 2.2 KB
git-merge-one-file.sh -rwxr-xr-x 3.4 KB
git-merge-resolve.sh -rwxr-xr-x 944 bytes
git-mergetool--lib.sh -rw-r--r-- 7.4 KB
git-mergetool.sh -rwxr-xr-x 9.2 KB
git-p4.py -rwxr-xr-x 119.3 KB
git-parse-remote.sh -rw-r--r-- 2.3 KB
git-pull.sh -rwxr-xr-x 8.7 KB
git-quiltimport.sh -rwxr-xr-x 3.3 KB
git-rebase--am.sh -rw-r--r-- 2.4 KB
git-rebase--interactive.sh -rw-r--r-- 27.8 KB
git-rebase--merge.sh -rw-r--r-- 3.7 KB
git-rebase.sh -rwxr-xr-x 15.7 KB
git-relink.perl -rwxr-xr-x 4.0 KB
git-remote-testgit.sh -rwxr-xr-x 2.7 KB
git-request-pull.sh -rwxr-xr-x 3.8 KB
git-send-email.perl -rwxr-xr-x 43.8 KB
git-sh-i18n.sh -rw-r--r-- 2.0 KB
git-sh-setup.sh -rw-r--r-- 8.1 KB
git-stash.sh -rwxr-xr-x 13.3 KB
git-submodule.sh -rwxr-xr-x 31.4 KB
git-svn.perl -rwxr-xr-x 60.5 KB
git-web--browse.sh -rwxr-xr-x 4.3 KB
git.c -rw-r--r-- 19.5 KB
git.rc -rw-r--r-- 566 bytes
git.spec.in -rw-r--r-- 11.1 KB
gpg-interface.c -rw-r--r-- 5.6 KB
gpg-interface.h -rw-r--r-- 930 bytes
graph.c -rw-r--r-- 34.5 KB
graph.h -rw-r--r-- 3.9 KB
grep.c -rw-r--r-- 41.3 KB
grep.h -rw-r--r-- 4.8 KB
hashmap.c -rw-r--r-- 6.3 KB
hashmap.h -rw-r--r-- 2.5 KB
help.c -rw-r--r-- 11.0 KB
help.h -rw-r--r-- 1.1 KB
hex.c -rw-r--r-- 2.3 KB
http-backend.c -rw-r--r-- 15.7 KB
http-fetch.c -rw-r--r-- 2.3 KB
http-push.c -rw-r--r-- 50.3 KB
http-walker.c -rw-r--r-- 13.8 KB
http.c -rw-r--r-- 40.4 KB
http.h -rw-r--r-- 6.3 KB
ident.c -rw-r--r-- 10.3 KB
imap-send.c -rw-r--r-- 32.1 KB
khash.h -rw-r--r-- 12.6 KB
kwset.c -rw-r--r-- 20.5 KB
kwset.h -rw-r--r-- 2.6 KB
levenshtein.c -rw-r--r-- 2.5 KB
levenshtein.h -rw-r--r-- 203 bytes
line-log.c -rw-r--r-- 30.5 KB
line-log.h -rw-r--r-- 1.8 KB
line-range.c -rw-r--r-- 6.5 KB
line-range.h -rw-r--r-- 1.3 KB
list-objects.c -rw-r--r-- 6.0 KB
list-objects.h -rw-r--r-- 407 bytes
ll-merge.c -rw-r--r-- 10.1 KB
ll-merge.h -rw-r--r-- 567 bytes
lockfile.c -rw-r--r-- 7.7 KB
lockfile.h -rw-r--r-- 3.3 KB
log-tree.c -rw-r--r-- 22.3 KB
log-tree.h -rw-r--r-- 1.2 KB
mailmap.c -rw-r--r-- 9.1 KB
mailmap.h -rw-r--r-- 271 bytes
match-trees.c -rw-r--r-- 8.0 KB
merge-blobs.c -rw-r--r-- 2.6 KB
merge-blobs.h -rw-r--r-- 194 bytes
merge-recursive.c -rw-r--r-- 57.8 KB
merge-recursive.h -rw-r--r-- 1.6 KB
merge.c -rw-r--r-- 2.4 KB
mergesort.c -rw-r--r-- 1.5 KB
mergesort.h -rw-r--r-- 574 bytes
name-hash.c -rw-r--r-- 6.2 KB
notes-cache.c -rw-r--r-- 2.2 KB
notes-cache.h -rw-r--r-- 500 bytes
notes-merge.c -rw-r--r-- 22.7 KB
notes-merge.h -rw-r--r-- 2.9 KB
notes-utils.c -rw-r--r-- 4.5 KB
notes-utils.h -rw-r--r-- 1.1 KB
notes.c -rw-r--r-- 36.1 KB
notes.h -rw-r--r-- 11.2 KB
object.c -rw-r--r-- 9.5 KB
object.h -rw-r--r-- 4.5 KB
pack-bitmap-write.c -rw-r--r-- 12.4 KB
pack-bitmap.c -rw-r--r-- 25.1 KB
pack-bitmap.h -rw-r--r-- 1.8 KB
pack-check.c -rw-r--r-- 5.0 KB
pack-objects.c -rw-r--r-- 2.1 KB
pack-objects.h -rw-r--r-- 1.9 KB
pack-revindex.c -rw-r--r-- 7.0 KB
pack-revindex.h -rw-r--r-- 410 bytes
pack-write.c -rw-r--r-- 10.3 KB
pack.h -rw-r--r-- 3.2 KB
pager.c -rw-r--r-- 3.3 KB
parse-options-cb.c -rw-r--r-- 2.7 KB
parse-options.c -rw-r--r-- 17.3 KB
parse-options.h -rw-r--r-- 8.9 KB
patch-delta.c -rw-r--r-- 2.2 KB
patch-ids.c -rw-r--r-- 2.4 KB
patch-ids.h -rw-r--r-- 490 bytes
path.c -rw-r--r-- 18.5 KB
pathspec.c -rw-r--r-- 14.1 KB
pathspec.h -rw-r--r-- 3.2 KB
pkt-line.c -rw-r--r-- 4.5 KB
pkt-line.h -rw-r--r-- 3.0 KB
preload-index.c -rw-r--r-- 2.5 KB
pretty.c -rw-r--r-- 42.5 KB
prio-queue.c -rw-r--r-- 1.9 KB
prio-queue.h -rw-r--r-- 1.5 KB
progress.c -rw-r--r-- 6.1 KB
progress.h -rw-r--r-- 504 bytes
prompt.c -rw-r--r-- 1.3 KB
prompt.h -rw-r--r-- 207 bytes
quote.c -rw-r--r-- 10.2 KB
quote.h -rw-r--r-- 2.8 KB
reachable.c -rw-r--r-- 4.6 KB
reachable.h -rw-r--r-- 304 bytes
read-cache.c -rw-r--r-- 61.0 KB
reflog-walk.c -rw-r--r-- 8.1 KB
reflog-walk.h -rw-r--r-- 773 bytes
refs.c -rw-r--r-- 104.8 KB
refs.h -rw-r--r-- 12.6 KB
remote-curl.c -rw-r--r-- 24.7 KB
remote-testsvn.c -rw-r--r-- 8.4 KB
remote.c -rw-r--r-- 55.8 KB
remote.h -rw-r--r-- 7.1 KB
replace_object.c -rw-r--r-- 2.9 KB
rerere.c -rw-r--r-- 17.6 KB
rerere.h -rw-r--r-- 804 bytes
resolve-undo.c -rw-r--r-- 4.3 KB
resolve-undo.h -rw-r--r-- 612 bytes
revision.c -rw-r--r-- 90.3 KB
revision.h -rw-r--r-- 8.0 KB
run-command.c -rw-r--r-- 17.8 KB
run-command.h -rw-r--r-- 3.3 KB
send-pack.c -rw-r--r-- 11.2 KB
send-pack.h -rw-r--r-- 428 bytes
sequencer.c -rw-r--r-- 32.0 KB
sequencer.h -rw-r--r-- 1.0 KB
server-info.c -rw-r--r-- 5.7 KB
setup.c -rw-r--r-- 22.8 KB
sh-i18n--envsubst.c -rw-r--r-- 10.3 KB
sha1-array.c -rw-r--r-- 1.2 KB
sha1-array.h -rw-r--r-- 583 bytes
sha1-lookup.c -rw-r--r-- 9.2 KB
sha1-lookup.h -rw-r--r-- 403 bytes
sha1_file.c -rw-r--r-- 85.4 KB
sha1_name.c -rw-r--r-- 35.8 KB
shallow.c -rw-r--r-- 17.6 KB
shell.c -rw-r--r-- 5.1 KB
shortlog.h -rw-r--r-- 463 bytes
show-index.c -rw-r--r-- 2.2 KB
sideband.c -rw-r--r-- 3.4 KB
sideband.h -rw-r--r-- 262 bytes
sigchain.c -rw-r--r-- 969 bytes
sigchain.h -rw-r--r-- 215 bytes
split-index.c -rw-r--r-- 9.2 KB
split-index.h -rw-r--r-- 1.1 KB
strbuf.c -rw-r--r-- 13.3 KB
strbuf.h -rw-r--r-- 7.0 KB
streaming.c -rw-r--r-- 11.7 KB
streaming.h -rw-r--r-- 504 bytes
string-list.c -rw-r--r-- 7.5 KB
string-list.h -rw-r--r-- 4.9 KB
submodule.c -rw-r--r-- 31.8 KB
submodule.h -rw-r--r-- 1.9 KB
symlinks.c -rw-r--r-- 9.3 KB
tag.c -rw-r--r-- 3.2 KB
tag.h -rw-r--r-- 508 bytes
tar.h -rw-r--r-- 644 bytes
test-chmtime.c -rw-r--r-- 2.6 KB
test-config.c -rw-r--r-- 3.8 KB
test-ctype.c -rw-r--r-- 918 bytes
test-date.c -rw-r--r-- 1.5 KB
test-delta.c -rw-r--r-- 1.8 KB
test-dump-cache-tree.c -rw-r--r-- 1.6 KB
test-dump-split-index.c -rw-r--r-- 810 bytes
test-genrandom.c -rw-r--r-- 722 bytes
test-hashmap.c -rw-r--r-- 6.1 KB
test-index-version.c -rw-r--r-- 258 bytes
test-line-buffer.c -rw-r--r-- 2.1 KB
test-match-trees.c -rw-r--r-- 590 bytes
test-mergesort.c -rw-r--r-- 924 bytes
test-mktemp.c -rw-r--r-- 269 bytes
test-parse-options.c -rw-r--r-- 3.4 KB
test-path-utils.c -rw-r--r-- 3.5 KB
test-prio-queue.c -rw-r--r-- 621 bytes
test-read-cache.c -rw-r--r-- 202 bytes
test-regex.c -rw-r--r-- 534 bytes
test-revision-walking.c -rw-r--r-- 1.4 KB
test-run-command.c -rw-r--r-- 827 bytes
test-scrap-cache-tree.c -rw-r--r-- 386 bytes
test-sha1-array.c -rw-r--r-- 936 bytes
test-sha1.c -rw-r--r-- 941 bytes
test-sha1.sh -rwxr-xr-x 1.9 KB
test-sigchain.c -rw-r--r-- 344 bytes
test-string-list.c -rw-r--r-- 2.5 KB
test-subprocess.c -rw-r--r-- 393 bytes
test-svn-fe.c -rw-r--r-- 1.3 KB
test-urlmatch-normalization.c -rw-r--r-- 1.2 KB
test-wildmatch.c -rw-r--r-- 635 bytes
thread-utils.c -rw-r--r-- 1.3 KB
thread-utils.h -rw-r--r-- 241 bytes
trace.c -rw-r--r-- 10.2 KB
trace.h -rw-r--r-- 3.5 KB
trailer.c -rw-r--r-- 20.9 KB
trailer.h -rw-r--r-- 148 bytes
transport-helper.c -rw-r--r-- 34.3 KB
transport.c -rw-r--r-- 35.1 KB
transport.h -rw-r--r-- 7.0 KB
tree-diff.c -rw-r--r-- 17.6 KB
tree-walk.c -rw-r--r-- 21.4 KB
tree-walk.h -rw-r--r-- 2.2 KB
tree.c -rw-r--r-- 6.1 KB
tree.h -rw-r--r-- 945 bytes
unicode_width.h -rw-r--r-- 6.6 KB
unimplemented.sh -rw-r--r-- 100 bytes
unix-socket.c -rw-r--r-- 2.4 KB
unix-socket.h -rw-r--r-- 158 bytes
unpack-trees.c -rw-r--r-- 47.8 KB
unpack-trees.h -rw-r--r-- 2.2 KB
update_unicode.sh -rwxr-xr-x 1.1 KB
upload-pack.c -rw-r--r-- 20.2 KB
url.c -rw-r--r-- 2.8 KB
url.h -rw-r--r-- 492 bytes
urlmatch.c -rw-r--r-- 16.5 KB
urlmatch.h -rw-r--r-- 2.0 KB
usage.c -rw-r--r-- 3.3 KB
userdiff.c -rw-r--r-- 9.2 KB
userdiff.h -rw-r--r-- 646 bytes
utf8.c -rw-r--r-- 15.0 KB
utf8.h -rw-r--r-- 1.7 KB
varint.c -rw-r--r-- 660 bytes
varint.h -rw-r--r-- 168 bytes
version.c -rw-r--r-- 651 bytes
version.h -rw-r--r-- 180 bytes
versioncmp.c -rw-r--r-- 2.1 KB
walker.c -rw-r--r-- 7.3 KB
walker.h -rw-r--r-- 1.1 KB
wildmatch.c -rw-r--r-- 7.8 KB
wildmatch.h -rw-r--r-- 346 bytes
wrap-for-bin.sh -rw-r--r-- 707 bytes
wrapper.c -rw-r--r-- 11.7 KB
write_or_die.c -rw-r--r-- 2.1 KB
ws.c -rw-r--r-- 9.6 KB
wt-status.c -rw-r--r-- 43.4 KB
wt-status.h -rw-r--r-- 2.7 KB
xdiff-interface.c -rw-r--r-- 7.0 KB
xdiff-interface.h -rw-r--r-- 944 bytes
zlib.c -rw-r--r-- 6.1 KB

README

back to top