[6.0] 61c193889 Fix shard director in pipe mode

Reza Naghibi reza at naghibi.com
Wed Aug 19 13:17:08 UTC 2020


commit 61c193889a1d1ba810100e278faaa0f7bc2f9a3a
Author: Reza Naghibi <reza at naghibi.com>
Date:   Mon Aug 17 11:35:18 2020 -0400

    Fix shard director in pipe mode
    
    Switch the ctx and workspace to the req when resolving in pipe mode.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 5a17db15a..0e6e1ab59 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -352,7 +352,7 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
 	v1a.req = req->acct.req_hdrbytes;
 	req->acct.req_hdrbytes = 0;
 
-	req->res_mode = RES_PIPE;
+	assert(req->res_mode & RES_PIPE);
 
 	pfd = vbe_dir_getfd(req->wrk, bp, bo, 0);
 
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 3b6e4b71f..14e569df1 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -193,8 +193,11 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo)
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
+	req->res_mode = RES_PIPE;
+
 	d = vdi_resolve(req->wrk, bo);
 	if (d == NULL || d->http1pipe == NULL) {
+		req->res_mode = 0;
 		VSLb(bo->vsl, SLT_VCL_Error, "Backend does not support pipe");
 		return (SC_TX_ERROR);
 	}
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 846d75a6a..f6e8b67d2 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -759,7 +759,13 @@ vmod_shard_resolve(const struct director *dir, struct worker *wrk,
 	ctx->sp = bo->sp;
 	ctx->now = bo->t_prev;
 	ctx->ws = bo->ws;
-	ctx->method	= VCL_MET_BACKEND_FETCH;
+	if (bo->req) {
+		CHECK_OBJ_NOTNULL(bo->req, REQ_MAGIC);
+		if (bo->req->res_mode & RES_PIPE) {
+			ctx->req = bo->req;
+			ctx->ws = ctx->req->ws;
+		}
+	}
 
 	pp = vmod_shard_param_read(ctx, vshard,
 				   vshard->param, pstk, "shard_resolve");


More information about the varnish-commit mailing list