[master] f0e9df843 vrb: Turn BS_TAKEN into a request flag

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Jul 3 09:39:05 UTC 2024


commit f0e9df843d28bb55e9acea9b73ae4ccc658d033f
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jun 24 17:53:24 2024 +0200

    vrb: Turn BS_TAKEN into a request flag
    
    This body status would conflict with a BS_TRAILERS body status in the h2
    case where the body is received and sent asynchronously by two different
    workers.

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 05dc40ce9..914ce8010 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -141,11 +141,8 @@ Bereq_Rollback(VRT_CTX)
 	bo = ctx->bo;
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
-	if (bo->htc != NULL) {
-		assert(bo->htc->body_status != BS_TAKEN);
-		if (bo->htc->body_status != BS_NONE)
-			bo->htc->doclose = SC_RESP_CLOSE;
-	}
+	if (bo->htc != NULL && bo->htc->body_status != BS_NONE)
+		bo->htc->doclose = SC_RESP_CLOSE;
 
 	vbf_cleanup(bo);
 	VCL_TaskLeave(ctx, bo->privs);
diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index fa4b4062b..49179a9d9 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -207,7 +207,7 @@ VRB_Iterate(struct worker *wrk, struct vsl_log *vsl,
 	}
 	if (req->req_body_status == BS_NONE)
 		return (0);
-	if (req->req_body_status == BS_TAKEN) {
+	if (req->req_body_taken) {
 		VSLb(vsl, SLT_VCL_Error,
 		    "Uncached req.body can only be consumed once.");
 		return (-1);
@@ -219,7 +219,7 @@ VRB_Iterate(struct worker *wrk, struct vsl_log *vsl,
 	}
 	Lck_Lock(&req->sp->mtx);
 	if (req->req_body_status->avail > 0) {
-		req->req_body_status = BS_TAKEN;
+		req->req_body_taken = 1;
 		i = 0;
 	} else
 		i = -1;
@@ -277,6 +277,7 @@ VRB_Free(struct req *req)
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
+	req->req_body_taken = 0;
 	if (req->body_oc == NULL) {
 		AZ(req->req_body_cached);
 		return;
diff --git a/include/tbl/body_status.h b/include/tbl/body_status.h
index 39c45b4fb..e9464381f 100644
--- a/include/tbl/body_status.h
+++ b/include/tbl/body_status.h
@@ -38,7 +38,6 @@ BODYSTATUS(ERROR,	error,		1,	-1,	0)
 BODYSTATUS(CHUNKED,	chunked,	2,	1,	0)
 BODYSTATUS(LENGTH,	length,		3,	1,	1)
 BODYSTATUS(EOF,		eof,		4,	1,	0)
-BODYSTATUS(TAKEN,	taken,		5,	0,	0)
 #undef BODYSTATUS
 
 /*lint -restore */
diff --git a/include/tbl/req_flags.h b/include/tbl/req_flags.h
index 282bd92ea..cee216749 100644
--- a/include/tbl/req_flags.h
+++ b/include/tbl/req_flags.h
@@ -42,6 +42,7 @@ REQ_FLAG(want100cont,		0, 0, "")
 REQ_FLAG(late100cont,		0, 0, "")
 REQ_FLAG(req_reset,		0, 0, "")
 REQ_FLAG(req_body_cached,	0, 0, "")
+REQ_FLAG(req_body_taken,	0, 0, "")
 #define REQ_BEREQ_FLAG(lower, vcl_r, vcl_w, doc) \
 	REQ_FLAG(lower, vcl_r, vcl_w, doc)
 #include "tbl/req_bereq_flags.h"


More information about the varnish-commit mailing list