[PATCH 1/8] Resource cleanup in cnt_error() when Transient is full.

Martin Blix Grydeland martin at varnish-software.com
Mon Mar 18 17:57:22 CET 2013


Fixes: #1283
---
 bin/varnishd/cache/cache_hash.c    |    3 +-
 bin/varnishd/cache/cache_req_fsm.c |    5 ++++
 bin/varnishtest/tests/r01283.vtc   |   57 ++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 bin/varnishtest/tests/r01283.vtc

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index db906ec..b680605 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -682,7 +682,8 @@ HSH_Deref(struct dstat *ds, struct objcore *oc, struct object **oo)
 
 		BAN_DestroyObj(oc);
 		AZ(oc->ban);
-	}
+	} else
+		AZ(oc->refcnt);
 
 	if (oc->methods != NULL) {
 		oc_freeobj(oc);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index b2bdd50..a7f8778 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -280,11 +280,16 @@ cnt_error(struct worker *wrk, struct req *req)
 	if (req->obj == NULL) {
 		req->doclose = SC_OVERLOAD;
 		req->director = NULL;
+		AZ(HSH_Deref(&wrk->stats, req->objcore, NULL));
+		req->objcore = NULL;
 		http_Teardown(bo->beresp);
 		http_Teardown(bo->bereq);
+		VBO_DerefBusyObj(wrk, &req->busyobj);
+		AZ(req->busyobj);
 		return (REQ_FSM_DONE);
 	}
 	CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
+	AZ(req->objcore);
 	req->obj->vxid = bo->vsl->wid;
 	req->obj->exp.entered = req->t_req;
 
diff --git a/bin/varnishtest/tests/r01283.vtc b/bin/varnishtest/tests/r01283.vtc
new file mode 100644
index 0000000..668deda
--- /dev/null
+++ b/bin/varnishtest/tests/r01283.vtc
@@ -0,0 +1,57 @@
+varnishtest "#1283 - Test failure to allocate object for error (transient full)"
+
+server s1 {
+	rxreq
+	expect req.url == "/obj1"
+	txresp -bodylen 1048000
+	rxreq
+	expect req.url == "/obj2"
+	txresp -bodylen 1048000
+} -start
+
+varnish v1 -arg "-p nuke_limit=0" -storage "-smalloc,1m -sTransient=malloc,1m" -vcl+backend {
+	sub vcl_recv {
+		if (req.http.x-do-error) {
+			error 500;
+		}
+	}
+} -start
+
+varnish v1 -expect n_objcore == 0
+
+client c1 {
+	# Fill s0
+	txreq -url "/obj1"
+	rxresp
+	expect resp.status == 200
+} -run
+
+varnish v1 -expect SMA.s0.g_bytes > 1048000
+varnish v1 -expect SMA.s0.g_space < 200
+
+client c1 {
+	# Fill transient
+	txreq -url "/obj2"
+	rxresp
+	expect resp.status == 200
+} -run
+
+varnish v1 -expect SMA.Transient.g_bytes > 1048000
+varnish v1 -expect SMA.Transient.g_space < 200
+varnish v1 -expect SMA.Transient.c_fail == 0
+
+client c1 {
+	# Trigger vcl_error. Don't wait for reply as Varnish will not send one
+	# due to Transient full
+	txreq -hdr "X-Do-Error: true"
+	delay 1
+} -run
+
+varnish v1 -expect SMA.Transient.c_fail == 1
+
+client c1 {
+	# Check that Varnish is still alive
+	txreq -url "/obj1"
+	rxresp
+	expect resp.status == 200
+} -run
-- 
1.7.10.4




More information about the varnish-dev mailing list