[master] ba8e58b49 Avoid spreading req.body status logic all over the place

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 19 14:55:06 UTC 2020


commit ba8e58b494b7bfee3ae754f3c6916e568648e5e3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 19 14:54:31 2020 +0000

    Avoid spreading req.body status logic all over the place

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b1f8bdc40..0d66cea58 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -389,7 +389,6 @@ struct busyobj {
 	 * is recycled.
 	 */
 	unsigned		retries;
-	enum req_body_state_e	initial_req_body_status;
 	struct req		*req;
 	struct sess		*sp;
 	struct worker		*wrk;
@@ -406,6 +405,8 @@ struct busyobj {
 	struct objcore		*stale_oc;
 	struct objcore		*fetch_objcore;
 
+	const char		*no_retry;
+
 	struct http_conn	*htc;
 
 	struct pool_task	fetch_task;
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 4253e21bf..06bd94ddc 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -240,7 +240,6 @@ vbf_stp_mkbereq(struct worker *wrk, struct busyobj *bo)
 	bo->ws_bo = WS_Snapshot(bo->ws);
 	HTTP_Clone(bo->bereq, bo->bereq0);
 
-	bo->initial_req_body_status = bo->req->req_body_status;
 	if (bo->req->req_body_status == REQ_BODY_NONE) {
 		bo->req = NULL;
 		ObjSetState(bo->wrk, bo->fetch_objcore, BOS_REQ_DONE);
@@ -270,12 +269,9 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
 
 	assert(bo->fetch_objcore->boc->state <= BOS_REQ_DONE);
 
-	if (bo->fetch_objcore->boc->state == BOS_REQ_DONE &&
-	    bo->initial_req_body_status != REQ_BODY_NONE &&
-	    bo->bereq_body == NULL) {
-		/* We have already released the req and there was a
-		 * request body that was not cached. Too late to retry. */
-		VSLb(bo->vsl, SLT_Error, "req.body already consumed");
+	if (bo->no_retry != NULL) {
+		VSLb(bo->vsl, SLT_Error,
+		    "Retry not possible, %s", bo->no_retry);
 		return (F_STP_FAIL);
 	}
 
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 79b6ceb35..64547f8e3 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -120,6 +120,9 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
 			V1L_Chunked(wrk);
 		i = VRB_Iterate(wrk, bo->vsl, bo->req, vbf_iter_req_body, bo);
 
+		if (bo->req->req_body_status != REQ_BODY_CACHED)
+			bo->no_retry = "req.body not cached";
+
 		if (bo->req->req_body_status == REQ_BODY_FAIL) {
 			/*
 			 * XXX: (#2332) We should test to see if the backend


More information about the varnish-commit mailing list