upload-pack: allow stateless client EOF just prior to haves
authorDaniel Duvall <redacted>
Sat, 31 Oct 2020 02:39:02 +0000 (19:39 -0700)
committerJunio C Hamano <redacted>
Sat, 31 Oct 2020 04:18:10 +0000 (21:18 -0700)
commitfb3d1a083f776f02caa514cad8b232d8b974641f
tree70bef9495daacaa1cf359f9fc1492c90de539d9d
parente2850a27a95c6f5b141dd88398b1702d2e524a81
upload-pack: allow stateless client EOF just prior to haves

During stateless packfile negotiation where a depth is given, stateless
RPC clients (e.g. git-remote-curl) will send multiple upload-pack
requests with the first containing only the
wants/shallows/deepens/filters and the subsequent containing haves/done.

When upload-pack handles such requests, entering get_common_commits
without checking whether the client has hung up can result in unexpected
EOF during the negotiation loop and a die() with message "fatal: the
remote end hung up unexpectedly".

Real world effects include:

 - A client speaking to git-http-backend via a server that doesn't check
   the exit codes of CGIs (e.g. mod_cgi) doesn't know and doesn't care
   about the fatal. It continues to process the response body as normal.

 - A client speaking to a server that does check the exit code and
   returns an errant HTTP status as a result will fail with the message
   "error: RPC failed; HTTP 500 curl 22 The requested URL returned error:
   500."

 - Admins running servers that surface the failure must workaround it by
   patching code that handles execution of git-http-backend to ignore exit
   codes or take other heuristic approaches.

 - Admins may have to deal with "hung up unexpectedly" log spam related
   to the failures even in cases where the exit code isn't surfaced as an
   HTTP server-side error status.

To avoid these EOF related fatals, have upload-pack gently peek for an
EOF between the sending of shallow/unshallow lines (followed by flush)
and the reading of client haves. If the client has hung up at this
point, exit normally.

Signed-off-by: Daniel Duvall <redacted>
Signed-off-by: Junio C Hamano <redacted>
t/t5530-upload-pack-error.sh
upload-pack.c
git clone https://git.99rst.org/PROJECT