From 51a1b5eb6141be4e1ada5a4b3a5b1f42923079e2 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@warmcat.com>
Date: Fri, 30 Nov 2018 08:46:38 +0800
Subject: [PATCH] cgi: use transaction_complete when stdout goes away

transaction_complete includes processing for the case we are holding
an output-side buflist, and arranges for it to be sent before the
connection is actually closed.

This stops very slow links not being ablet to use git clone via
cgi mount, because the close races the flushing of the output-side
buflist and in the case the connection is bad, closes before
everything was sent.
---
 lib/core/dummy-callback.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/core/dummy-callback.c b/lib/core/dummy-callback.c
index 8fd18be9..c99270fe 100644
--- a/lib/core/dummy-callback.c
+++ b/lib/core/dummy-callback.c
@@ -155,7 +155,9 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
 						   LWS_WRITE_HTTP_FINAL);
 
 			/* always close after sending it */
-			return -1;
+			if (lws_http_transaction_completed(wsi))
+				return -1;
+			return 0;
 		}
 #endif
 #if defined(LWS_WITH_HTTP_PROXY)
@@ -459,10 +461,12 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
 			lwsl_debug("LWS_CALLBACK_CGI_TERMINATED: ending\n");
 			wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_CHUNK_END;
 			lws_callback_on_writable(wsi);
-			lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, 3);
+			lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, 10);
 			break;
 		}
-		return -1;
+		if (lws_http_transaction_completed(wsi))
+			return -1;
+		return 0;
 
 	case LWS_CALLBACK_CGI_STDIN_DATA:  /* POST body for stdin */
 		args = (struct lws_cgi_args *)in;
-- 
GitLab