[master] df1cdb8 Avoid duplicate Begin/End records on ESI subrequests

Martin Blix Grydeland martin at varnish-software.com
Thu Feb 27 16:02:57 CET 2014


commit df1cdb82cb1c103c1ae610fc6e6ebb4e75de054f
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Feb 27 15:34:38 2014 +0100

    Avoid duplicate Begin/End records on ESI subrequests
    
    When starting an ESI subrequest, make sure that the Begin/End headers
    are only output once, formatted for ESI.
    
    Fixes: #1441

diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index e76b437..65ad51d 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -61,6 +61,7 @@ ved_include(struct req *preq, const char *src, const char *host)
 
 	req = SES_GetReq(wrk, preq->sp);
 	req->req_body_status = REQ_BODY_NONE;
+	AN(req->vsl->wid & VSL_CLIENTMARKER);
 	VSLb(req->vsl, SLT_Begin, "req %u esi", preq->vsl->wid & VSL_IDENTMASK);
 	VSLb(preq->vsl, SLT_Link, "req %u esi", req->vsl->wid & VSL_IDENTMASK);
 	req->esi_level = preq->esi_level + 1;
@@ -115,8 +116,8 @@ ved_include(struct req *preq, const char *src, const char *host)
 		(void)usleep(10000);
 	}
 
-	VSLb(req->vsl, SLT_End, "%s", "");
-	req->vsl->wid = 0;
+	/* Make sure the VSL id has been released */
+	AZ(req->vsl->wid);
 
 	/* Reset the workspace */
 	WS_Reset(wrk->aws, wrk_ws_wm);	/* XXX ? */
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 83ed4cd..96a2507 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -159,6 +159,9 @@ ses_sess_pool_task(struct worker *wrk, void *arg)
 
 	req = SES_GetReq(wrk, sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	AN(req->vsl->wid & VSL_CLIENTMARKER);
+	VSLb(req->vsl, SLT_Begin, "req %u rxreq", sp->vxid & VSL_IDENTMASK);
+	VSL(SLT_Link, sp->vxid, "req %u rxreq", req->vsl->wid & VSL_IDENTMASK);
 
 	sp->sess_step = S_STP_NEWREQ;
 	ses_req_pool_task(wrk, req);
@@ -389,9 +392,6 @@ SES_GetReq(struct worker *wrk, struct sess *sp)
 	sz = cache_param->vsl_buffer;
 	VSL_Setup(req->vsl, p, sz);
 	req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER;
-	VSLb(req->vsl, SLT_Begin, "req %u rxreq", sp->vxid & VSL_IDENTMASK);
-	VSL(SLT_Link, req->sp->vxid, "req %u rxreq",
-	    req->vsl->wid & VSL_IDENTMASK);
 	p += sz;
 	p = (void*)PRNDUP(p);
 
diff --git a/bin/varnishtest/tests/r01441.vtc b/bin/varnishtest/tests/r01441.vtc
new file mode 100644
index 0000000..ec9553d
--- /dev/null
+++ b/bin/varnishtest/tests/r01441.vtc
@@ -0,0 +1,40 @@
+varnishtest "Session grouping on ESI"
+
+server s1 {
+	rxreq
+	expect req.url == "/"
+	txresp -body "<esi:include src=\"/include\"/>"
+
+	rxreq
+	expect req.url == "/include"
+	txresp -body "included"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+		if (bereq.url == "/") {
+			set beresp.do_esi = true;
+		}
+	}
+} -start
+
+logexpect l1 -v v1 -g session {
+	expect 0 1000	Begin sess 0 HTTP/1
+	expect * =	End
+	expect 0 1001	Begin req 1000 rxreq
+	expect * =	End
+	expect 0 1002	Begin bereq 1001 fetch
+	expect * =	End
+	expect 0 1003	Begin req 1001 esi
+	expect * =	End
+	expect 0 1004	Begin bereq 1003 fetch
+	expect * =	End
+} -start
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+} -run
+
+logexpect l1 -wait



More information about the varnish-commit mailing list