[master] 8c0af33 Fix an attempt to double close a session.

Poul-Henning Kamp phk at FreeBSD.org
Mon May 11 10:46:41 CEST 2015


commit 8c0af33385c8045cea0574af26418f5480c13e50
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon May 11 08:45:22 2015 +0000

    Fix an attempt to double close a session.
    
    In future versions of HTTP requests can be terminated abnormally
    without ditching the entire session, and this change starts the
    transition to that logic.
    
    Fixes: #1732

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7c6a076..29aeaec 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -991,6 +991,7 @@ void VRG_dorange(struct req *req, const char *r);
 struct req *Req_New(const struct worker *, struct sess *);
 void Req_Release(struct req *);
 int Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req);
+void Req_Fail(struct req *req, enum sess_close reason);
 
 /* cache_session.c [SES] */
 struct sess *SES_New(struct sesspool *);
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 55a78ba..23c9925 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -59,7 +59,7 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
 	CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC);
 	if (act == VDP_FINI) {
 		if (vrg_priv->range_off < vrg_priv->range_high)
-			SES_Close(req->sp, SC_RANGE_SHORT);
+			Req_Fail(req, SC_RANGE_SHORT);
 		*priv = NULL;	/* struct on ws, no need to free */
 		return (0);
 	}
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 1804b1c..03c3557 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -203,3 +203,15 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 	WS_Reset(wrk->aws, NULL);
 	return (0);
 }
+
+/*----------------------------------------------------------------------
+ */
+
+void __match_proto__()
+Req_Fail(struct req *req, enum sess_close reason)
+{
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+
+	if (req->sp->fd >= 0)
+		SES_Close(req->sp, reason);
+}
diff --git a/bin/varnishtest/tests/r01732.vtc b/bin/varnishtest/tests/r01732.vtc
new file mode 100644
index 0000000..f738dec
--- /dev/null
+++ b/bin/varnishtest/tests/r01732.vtc
@@ -0,0 +1,38 @@
+varnishtest "range related panic"
+
+server s1 {
+	rxreq
+	txresp -nolen -hdr "Transfer-Encoding: chunked"
+	chunkedlen 10
+	chunkedlen 10
+	sema r1 sync 2
+	chunkedlen 10
+	chunkedlen 10
+	chunkedlen 10
+	chunkedlen 0
+	delay .1
+	sema r2 sync 2
+} -start
+
+varnish v1 -vcl+backend {
+} -start
+
+client c1 {
+	txreq -hdr "Range: bytes=0-100"
+	rxresphdrs
+	expect resp.status == 206
+	expect resp.http.Content-Range == "bytes 0-100/*"
+} -run
+
+delay .1
+sema r1 sync 2
+sema r2 sync 2
+delay .4
+
+client c1 {
+	txreq -hdr "Range: bytes=0-100"
+	rxresp
+	expect resp.status == 206
+	expect resp.http.Content-Range == "bytes 0-49/50"
+} -run
+



More information about the varnish-commit mailing list