Merge branch 'dt/smart-http-detect-server-going-away'

When the http server gives an incomplete response to a smart-http
rpc call, it could lead to client waiting for a full response that
will never come.  Teach the client side to notice this condition
and abort the transfer.

An improvement counterproposal has failed.
cf. <20161114194049.mktpsvgdhex2f4zv@sigill.intra.peff.net>

* dt/smart-http-detect-server-going-away:
  upload-pack: optionally allow fetching any sha1
  remote-curl: don't hang when a server dies before any output
This commit is contained in:
Junio C Hamano
2017-01-10 15:24:25 -08:00
5 changed files with 77 additions and 4 deletions

View File

@ -404,6 +404,7 @@ struct rpc_state {
size_t pos;
int in;
int out;
int any_written;
struct strbuf result;
unsigned gzip_request : 1;
unsigned initial_buffer : 1;
@ -460,6 +461,8 @@ static size_t rpc_in(char *ptr, size_t eltsize,
{
size_t size = eltsize * nmemb;
struct rpc_state *rpc = buffer_;
if (size)
rpc->any_written = 1;
write_or_die(rpc->in, ptr, size);
return size;
}
@ -663,6 +666,8 @@ retry:
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
rpc->any_written = 0;
err = run_slot(slot, NULL);
if (err == HTTP_REAUTH && !large_request) {
credential_fill(&http_auth);
@ -671,6 +676,9 @@ retry:
if (err != HTTP_OK)
err = -1;
if (!rpc->any_written)
err = -1;
curl_slist_free_all(headers);
free(gzip_body);
return err;