git-commit-vandalism/Documentation
Jeff King 83558686ce receive-pack: send keepalives during quiet periods
After a client has sent us the complete pack, we may spend
some time processing the data and running hooks. If the
client asked us to be quiet, receive-pack won't send any
progress data during the index-pack or connectivity-check
steps. And hooks may or may not produce their own progress
output. In these cases, the network connection is totally
silent from both ends.

Git itself doesn't care about this (it will wait forever),
but other parts of the system (e.g., firewalls,
load-balancers, etc) might hang up the connection. So we'd
like to send some sort of keepalive to let the network and
the client side know that we're still alive and processing.

We can use the same trick we did in 05e9515 (upload-pack:
send keepalive packets during pack computation, 2013-09-08).
Namely, we will send an empty sideband data packet every `N`
seconds that we do not relay any stderr data over the
sideband channel. As with 05e9515, this means that we won't
bother sending keepalives when there's actual progress data,
but will kick in when it has been disabled (or if there is a
lull in the progress data).

The concept is simple, but the details are subtle enough
that they need discussing here.

Before the client sends us the pack, we don't want to do any
keepalives. We'll have sent our ref advertisement, and we're
waiting for them to send us the pack (and tell us that they
support sidebands at all).

While we're receiving the pack from the client (or waiting
for it to start), there's no need for keepalives; it's up to
them to keep the connection active by sending data.
Moreover, it would be wrong for us to do so. When we are the
server in the smart-http protocol, we must treat our
connection as half-duplex. So any keepalives we send while
receiving the pack would potentially be buffered by the
webserver. Not only does this make them useless (since they
would not be delivered in a timely manner), but it could
actually cause a deadlock if we fill up the buffer with
keepalives. (It wouldn't be wrong to send keepalives in this
phase for a full-duplex connection like ssh; it's simply
pointless, as it is the client's responsibility to speak).

As soon as we've gotten all of the pack data, then the
client is waiting for us to speak, and we should start
keepalives immediately. From here until the end of the
connection, we send one any time we are not otherwise
sending data.

But there's a catch. Receive-pack doesn't know the moment
we've gotten all the data. It passes the descriptor to
index-pack, who reads all of the data, and then starts
resolving the deltas. We have to communicate that back.

To make this work, we instruct the sideband muxer to enable
keepalives in three phases:

  1. In the beginning, not at all.

  2. While reading from index-pack, wait for a signal
     indicating end-of-input, and then start them.

  3. Afterwards, always.

The signal from index-pack in phase 2 has to come over the
stderr channel which the muxer is reading. We can't use an
extra pipe because the portable run-command interface only
gives us stderr and stdout.

Stdout is already used to pass the .keep filename back to
receive-pack. We could also send a signal there, but then we
would find out about it in the main thread. And the
keepalive needs to be done by the async muxer thread (since
it's the one writing sideband data back to the client). And
we can't reliably signal the async thread from the main
thread, because the async code sometimes uses threads and
sometimes uses forked processes.

Therefore the signal must come over the stderr channel,
where it may be interspersed with other random
human-readable messages from index-pack. This patch makes
the signal a single NUL byte.  This is easy to parse, should
not appear in any normal stderr output, and we don't have to
worry about any timing issues (like seeing half the signal
bytes in one read(), and half in a subsequent one).

This is a bit ugly, but it's simple to code and should work
reliably.

Another option would be to stop using an async thread for
muxing entirely, and just poll() both stderr and stdout of
index-pack from the main thread. This would work for
index-pack (because we aren't doing anything useful in the
main thread while it runs anyway). But it would make the
connectivity check and the hook muxers much more
complicated, as they need to simultaneously feed the
sub-programs while reading their stderr.

The index-pack phase is the only one that needs this
signaling, so it could simply behave differently than the
other two. That would mean having two separate
implementations of copy_to_sideband (and the keepalive
code), though. And it still doesn't get rid of the
signaling; it just means we can write a nicer message like
"END_OF_INPUT" or something on stdout, since we don't have
to worry about separating it from the stderr cruft.

One final note: this signaling trick is only done with
index-pack, not with unpack-objects. There's no point in
doing it for the latter, because by definition it only kicks
in for a small number of objects, where keepalives are not
as useful (and this conveniently lets us avoid duplicating
the implementation).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-20 12:11:11 -07:00
..
howto new-command.txt: correct the command description file 2016-06-27 06:11:57 -07:00
RelNotes Sixth batch of topics for 2.10 2016-07-19 13:26:16 -07:00
technical Documentation/technical: signed merge tag format 2016-06-17 12:10:48 -07:00
.gitattributes
.gitignore doc: generate a list of valid merge tools 2013-02-02 21:46:52 -08:00
asciidoc.conf
blame-options.txt Merge branch 'ea/blame-progress' 2016-01-12 15:16:54 -08:00
build-docdep.perl
cat-texi.perl
cmd-list.perl command-list: prepare machinery for upcoming "common groups" section 2015-05-21 13:03:37 -07:00
CodingGuidelines CodingGuidelines: formatting HEAD in documentation 2016-06-28 08:36:45 -07:00
config.txt receive-pack: send keepalives during quiet periods 2016-07-20 12:11:11 -07:00
date-formats.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
diff-config.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
diff-format.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
diff-generate-patch.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
diff-options.txt Merge branch 'jk/diff-compact-heuristic' 2016-06-10 15:26:06 -07:00
docbook-xsl.css
docbook.xsl
everyday.txto Documentation: fix linkgit references 2016-05-09 15:44:14 -07:00
fetch-options.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
fix-texi.perl
fmt-merge-msg-config.txt Documentation: include 'merge.branchdesc' for merge and config as well 2015-05-28 12:38:46 -07:00
git-add.txt git-add doc: do not say working directory when you mean working tree 2016-01-21 09:06:35 -08:00
git-am.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-annotate.txt
git-apply.txt git-apply.txt: mention the behavior inside a subdir 2016-03-24 10:16:52 -07:00
git-archimport.txt
git-archive.txt docs: clarify remote restrictions for git-upload-archive 2014-02-28 09:55:35 -08:00
git-bisect-lk2009.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
git-bisect.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-blame.txt blame: add support for --[no-]progress option 2015-12-16 10:18:34 -08:00
git-branch.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-bundle.txt transport: drop support for git-over-rsync 2016-02-01 13:07:41 -08:00
git-cat-file.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-check-attr.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-check-ignore.txt Documentation: fix linkgit references 2016-05-09 15:44:14 -07:00
git-check-mailmap.txt
git-check-ref-format.txt Merge branch 'nd/doc-check-ref-format-typo' into maint 2015-12-11 11:14:15 -08:00
git-checkout-index.txt
git-checkout.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-cherry-pick.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-cherry.txt Documentation: revamp git-cherry(1) 2013-11-27 12:16:49 -08:00
git-citool.txt
git-clean.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-clone.txt Merge branch 'sb/clone-shallow-passthru' into maint 2016-07-11 10:44:12 -07:00
git-column.txt doc: remote author/documentation sections from more pages 2014-01-27 08:34:34 -08:00
git-commit-tree.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-commit.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-config.txt doc: typeset long options with argument as literal 2016-06-28 08:36:45 -07:00
git-count-objects.txt Documentation: fix misuses of "nor" 2014-03-31 15:16:22 -07:00
git-credential-cache--daemon.txt credential-cache: close stderr in daemon process 2014-09-16 11:11:58 -07:00
git-credential-cache.txt credential-cache--daemon: disallow relative socket path 2016-02-23 12:56:27 -08:00
git-credential-store.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-credential.txt Documentation: make AsciiDoc links always point to HTML files 2013-09-06 14:49:06 -07:00
git-cvsexportcommit.txt
git-cvsimport.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-cvsserver.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-daemon.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-describe.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-diff-files.txt
git-diff-index.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-diff-tree.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-diff.txt Documentation: fix misuses of "nor" 2014-03-31 15:16:22 -07:00
git-difftool.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-fast-export.txt doc: convert \--option to --option 2015-05-12 22:14:46 -07:00
git-fast-import.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-fetch-pack.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-fetch.txt fetch: reduce duplicate in ref update status lines with placeholder 2016-07-06 11:48:25 -07:00
git-filter-branch.txt doc: typeset '--' as literal 2016-06-28 08:36:45 -07:00
git-fmt-merge-msg.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-for-each-ref.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-format-patch.txt Merge branch 'tr/doc-tt' into maint 2016-07-06 13:06:34 -07:00
git-fsck-objects.txt
git-fsck.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-gc.txt doc: change configuration variables format 2016-06-08 12:04:55 -07:00
git-get-tar-commit-id.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-grep.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-gui.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-hash-object.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-help.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-http-backend.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
git-http-fetch.txt
git-http-push.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-imap-send.txt imap-send: use cURL automatically when NO_OPENSSL defined 2015-03-10 15:19:05 -07:00
git-index-pack.txt
git-init-db.txt
git-init.txt Merge branch 'tr/doc-tt' into maint 2016-07-06 13:06:34 -07:00
git-instaweb.txt doc: change configuration variables format 2016-06-08 12:04:55 -07:00
git-interpret-trailers.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-log.txt Merge branch 'mj/log-show-signature-conf' 2016-07-11 10:31:08 -07:00
git-ls-files.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-ls-remote.txt ls-remote: add support for showing symrefs 2016-01-19 10:07:56 -08:00
git-ls-tree.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
git-mailinfo.txt Merge branch 'va/mailinfo-doc-typofix' into maint 2016-05-26 13:17:14 -07:00
git-mailsplit.txt mailsplit: support unescaping mboxrd messages 2016-06-06 11:14:43 -07:00
git-merge-base.txt merge-base: teach "--fork-point" mode 2013-10-29 13:06:08 -07:00
git-merge-file.txt merge-file: clamp exit code to maximum 127 2015-10-29 12:10:23 -07:00
git-merge-index.txt
git-merge-one-file.txt
git-merge-tree.txt use 'tree-ish' instead of 'treeish' 2013-09-04 15:02:56 -07:00
git-merge.txt pull: pass --allow-unrelated-histories to "git merge" 2016-04-21 11:58:51 -07:00
git-mergetool--lib.txt
git-mergetool.txt mergetool: document the default for --[no-]prompt 2014-04-24 11:29:05 -07:00
git-mktag.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-mktree.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-mv.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-name-rev.txt use 'commit-ish' instead of 'committish' 2013-09-04 15:03:03 -07:00
git-notes.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-p4.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-pack-objects.txt pack-objects: warn on split packs disabling bitmaps 2016-04-28 09:58:14 -07:00
git-pack-redundant.txt
git-pack-refs.txt Documentation: remove --prune from pack-refs examples 2013-07-18 16:23:46 -07:00
git-parse-remote.txt
git-patch-id.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-prune-packed.txt Documentation: adjust document title underlining 2014-10-13 13:35:18 -07:00
git-prune.txt worktree: new place for "git prune --worktrees" 2015-06-29 08:48:44 -07:00
git-pull.txt pull --rebase: add --[no-]autostash flag 2016-03-21 13:30:36 -07:00
git-push.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-quiltimport.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
git-read-tree.txt Documentation: use "command-line" when used as a compound adjective, and fix other minor grammatical issues 2014-05-21 13:57:10 -07:00
git-rebase.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-receive-pack.txt *config.txt: stick to camelCase naming convention 2015-03-13 22:13:46 -07:00
git-reflog.txt git-reflog: add exists command 2015-07-21 14:08:14 -07:00
git-relink.txt
git-remote-ext.txt doc: add some crossrefs between manual pages 2014-11-11 14:47:04 -08:00
git-remote-fd.txt doc: add some crossrefs between manual pages 2014-11-11 14:47:04 -08:00
git-remote-helpers.txto
git-remote-testgit.txt
git-remote.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-repack.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-replace.txt doc: change environment variables format 2016-06-08 12:04:37 -07:00
git-request-pull.txt doc: show usage of branch description 2015-09-14 12:50:33 -07:00
git-rerere.txt *config.txt: stick to camelCase naming convention 2015-03-13 22:13:46 -07:00
git-reset.txt Merge branch 'jl/nor-or-nand-and' 2014-04-08 12:00:28 -07:00
git-rev-list.txt Merge branch 'jk/date-local' 2015-10-05 12:30:13 -07:00
git-rev-parse.txt rev-parse --parseopt: allow [*=?!] in argument hints 2015-07-15 10:30:54 -07:00
git-revert.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-rm.txt rm: better document side effects when removing a submodule 2014-01-07 14:34:06 -08:00
git-send-email.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-send-pack.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-sh-i18n--envsubst.txt
git-sh-i18n.txt
git-sh-setup.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
git-shell.txt doc: typeset short command-line options as literal 2016-06-28 08:20:52 -07:00
git-shortlog.txt
git-show-branch.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-show-index.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-show-ref.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-show.txt doc: convert \--option to --option 2015-05-12 22:14:46 -07:00
git-stage.txt Documentation: adjust document title underlining 2014-10-13 13:35:18 -07:00
git-stash.txt stash: allow "stash show" diff output configurable 2015-08-31 11:29:04 -07:00
git-status.txt Documentation: explain optional arguments better 2015-09-21 10:48:23 -07:00
git-stripspace.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-submodule.txt submodule update: learn --[no-]recommend-shallow option 2016-05-27 10:40:46 -07:00
git-svn.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-symbolic-ref.txt
git-tag.txt Merge branch 'mm/doc-tt' 2016-07-13 11:24:14 -07:00
git-tools.txt Documentation/git-tools: retire manually-maintained list 2015-07-28 13:21:59 -07:00
git-unpack-file.txt
git-unpack-objects.txt usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
git-update-index.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-update-ref.txt update-ref and tag: add --create-reflog arg 2015-07-21 14:08:35 -07:00
git-update-server-info.txt
git-upload-archive.txt Documentation: match underline with the text 2015-10-22 10:16:12 -07:00
git-upload-pack.txt upload-pack.c: use parse-options API 2016-05-31 10:17:20 -07:00
git-var.txt Documentation: the name of the system is 'Git', not 'git' 2013-02-01 13:53:33 -08:00
git-verify-commit.txt Merge branch 'dn/gpg-doc' into maint 2016-07-06 13:06:36 -07:00
git-verify-pack.txt git-verify-pack.txt: fix inconsistent spelling of "packfile" 2015-05-17 11:24:57 -07:00
git-verify-tag.txt verify-tag: add option to print raw gpg status information 2015-06-22 14:20:47 -07:00
git-web--browse.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
git-whatchanged.txt whatchanged: document its historical nature 2013-08-13 09:01:54 -07:00
git-worktree.txt Merge branch 'nd/worktree-cleanup-post-head-protection' 2016-07-06 13:38:11 -07:00
git-write-tree.txt
git.txt Sync with 2.9.2 2016-07-15 10:49:23 -07:00
gitattributes.txt userdiff: add built-in pattern for CSS 2016-06-03 14:45:56 -07:00
gitcli.txt Documentation: use "command-line" when used as a compound adjective, and fix other minor grammatical issues 2014-05-21 13:57:10 -07:00
gitcore-tutorial.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
gitcredentials.txt credential: let empty credential specs reset helper list 2016-02-26 10:58:14 -08:00
gitcvs-migration.txt doc: add 'everyday' to 'git help' 2014-10-10 16:02:26 -07:00
gitdiffcore.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
giteveryday.txt Documentation/everyday: match undefline with the text 2015-10-22 10:14:44 -07:00
gitglossary.txt doc: add 'everyday' to 'git help' 2014-10-10 16:02:26 -07:00
githooks.txt hooks: allow customizing where the hook directory is 2016-05-04 16:25:13 -07:00
gitignore.txt doc: change configuration variables format 2016-06-08 12:04:55 -07:00
gitk.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
gitmodules.txt doc: typeset long command-line options as literal 2016-06-28 08:36:45 -07:00
gitnamespaces.txt
gitremote-helpers.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
gitrepository-layout.txt Documentation/git-worktree: wordsmith worktree-related manpages 2015-07-20 11:07:18 -07:00
gitrevisions.txt Documentation: match underline with the text 2015-10-22 10:16:12 -07:00
gittutorial-2.txt Merge branch 'sn/tutorial-status-output-example' 2014-11-19 13:47:59 -08:00
gittutorial.txt transport: drop support for git-over-rsync 2016-02-01 13:07:41 -08:00
gitweb.conf.txt doc: more consistency in environment variables format 2016-06-08 12:04:37 -07:00
gitweb.txt doc: change environment variables format 2016-06-08 12:04:37 -07:00
gitworkflows.txt
glossary-content.txt Merge branch 'rn/glossary-typofix' into HEAD 2016-05-18 14:40:14 -07:00
howto-index.sh howto-index.sh: use the $( ... ) construct for command substitution 2014-04-17 11:14:57 -07:00
i18n.txt Documentation/i18n.txt: clarify character encoding support 2015-07-01 14:55:53 -07:00
install-doc-quick.sh
install-webdoc.sh install-webdoc.sh: use the $( ... ) construct for command substitution 2014-04-17 11:14:58 -07:00
line-range-format.txt Documentation: change -L:<regex> to -L:<funcname> 2015-04-20 11:05:50 -07:00
lint-gitlink.perl ci: validate "linkgit:" in documentation 2016-05-10 11:15:04 -07:00
mailmap.txt
Makefile Documentation/technical: describe signature formats 2016-06-17 11:39:05 -07:00
manpage-1.72.xsl
manpage-base-url.xsl.in
manpage-base.xsl
manpage-bold-literal.xsl
manpage-normal.xsl
manpage-quote-apos.xsl
manpage-suppress-sp.xsl
merge-config.txt doc: change environment variables format 2016-06-08 12:04:37 -07:00
merge-options.txt Merge branch 'kf/gpg-sig-verification-doc' 2016-05-17 14:38:39 -07:00
merge-strategies.txt merge-strategies.txt: fix typo 2016-02-22 10:42:52 -08:00
pretty-formats.txt Documentation: clarify signature verification 2016-05-13 12:37:44 -07:00
pretty-options.txt Merge branch 'tr/doc-tt' into maint 2016-07-06 13:06:34 -07:00
pull-fetch-param.txt docs: Explain the purpose of fetch's and pull's <refspec> parameter. 2014-06-12 09:59:13 -07:00
rev-list-options.txt rev-list: add optional progress reporting 2016-07-20 12:10:44 -07:00
revisions.txt doc: typeset HEAD and variants as literal 2016-06-28 08:36:45 -07:00
sequencer.txt
SubmittingPatches Documentation: add setup instructions for Travis CI 2016-05-02 11:31:44 -07:00
urls-remotes.txt Documentation: match underline with the text 2015-10-22 10:16:12 -07:00
urls.txt transport: drop support for git-over-rsync 2016-02-01 13:07:41 -08:00
user-manual.conf
user-manual.txt documentation: fix some typos 2016-03-03 13:43:36 -08:00