git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] smart-http: Don't deadlock on server failure

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 6, 2010, 21:19 UTC
Message-ID
<1281129584-18781-1-git-send-email-spearce@spearce.org>

If the remote HTTP server fails (e.g. returns 404 or 500) when we posted the RPC to it, we won't have sent anything to the background Git process that is supposed to handle the stream. Because we didn't send anything, its waiting for input from remote-curl, and remote-curl cannot read its response payload because doing so would lead to a deadlock.

Send the background task EOF on its input before we try to read its response back, that way it will break out of its read loop and terminate.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 This was found in Git 1.6.6.1, and exists since we added smart HTTP
 in 1.6.6.  Should apply at least to 'maint', if not older... :-)
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 8f169dd..c9d8f60 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -491,11 +491,12 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
 		rpc->len = n;
 		err |= post_rpc(rpc);
 	}
-	strbuf_read(&rpc->result, client.out, 0);
 
 	close(client.in);
-	close(client.out);
 	client.in = -1;
+	strbuf_read(&rpc->result, client.out, 0);
+
+	close(client.out);
 	client.out = -1;
 
 	err |= finish_command(&client);
-- 
1.7.2.1.52.g7f7860
Message 1 of 1 in “smart-http: Don't deadlock on server failure”
  1. smart-http: Don't deadlock on server failureShawn O. Pearce, Aug 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.