contrib/chg/hgclient.c
changeset 29602 4fc4b8cc9957
parent 29581 c66bc06f1bf6
child 29719 acf27be56d26
--- a/contrib/chg/hgclient.c	Mon Jul 18 11:27:27 2016 -0700
+++ b/contrib/chg/hgclient.c	Mon Jul 18 18:55:06 2016 +0100
@@ -126,10 +126,15 @@
 		return;  /* assumes input request */
 
 	size_t cursize = 0;
+	int emptycount = 0;
 	while (cursize < hgc->ctx.datasize) {
 		rsize = recv(hgc->sockfd, hgc->ctx.data + cursize,
 			     hgc->ctx.datasize - cursize, 0);
-		if (rsize < 0)
+		/* rsize == 0 normally indicates EOF, while it's also a valid
+		 * packet size for unix socket. treat it as EOF and abort if
+		 * we get many empty responses in a row. */
+		emptycount = (rsize == 0 ? emptycount + 1 : 0);
+		if (rsize < 0 || emptycount > 20)
 			abortmsg("failed to read data block");
 		cursize += rsize;
 	}