[PATCH 2/8] Properly clean up resources after STV_NewObject fails before jumping to error.

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


Fixes: #1284
---
 bin/varnishd/cache/cache_req_fsm.c |    4 ++-
 bin/varnishtest/tests/r01284.vtc   |   53 ++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 bin/varnishtest/tests/r01284.vtc

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index a7f8778..49a6732 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -487,6 +487,7 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
 	bo = req->busyobj;
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
@@ -571,7 +572,6 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
 
 	/* Create Vary instructions */
 	if (req->objcore->objhead != NULL) {
-		CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
 		vary = VRY_Create(req, bo->beresp);
 		if (vary != NULL) {
 			varyl = VSB_len(vary);
@@ -610,6 +610,8 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
 	if (req->obj == NULL) {
 		req->err_code = 503;
 		req->req_step = R_STP_ERROR;
+		AZ(HSH_Deref(&wrk->stats, req->objcore, NULL));
+		req->objcore = NULL;
 		VDI_CloseFd(&bo->vbc);
 		VBO_DerefBusyObj(wrk, &req->busyobj);
 		return (REQ_FSM_MORE);
diff --git a/bin/varnishtest/tests/r01284.vtc b/bin/varnishtest/tests/r01284.vtc
new file mode 100644
index 0000000..1289bd5
--- /dev/null
+++ b/bin/varnishtest/tests/r01284.vtc
@@ -0,0 +1,53 @@
+varnishtest "#1284 - Test resource cleanup after STV_NewObject fail in fetch"
+
+server s1 {
+	rxreq
+	expect req.url == "/obj1"
+	txresp -bodylen 1048000
+	rxreq
+	expect req.url == "/obj2"
+	txresp -bodylen 1048000
+	rxreq
+	expect req.url == "/obj3"
+	txresp -hdr "Long: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -hdr "Long2: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+} -start
+
+varnish v1 -arg "-p nuke_limit=0" -storage "-smalloc,1m -sTransient=malloc,1m" -vcl+backend {
+} -start
+
+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
+
+client c1 {
+	# No space for this object (more than 256 bytes in headers). Don't wait
+	# for reply as Varnish will not send one due to Transient full.
+	txreq -url "/obj3"
+	delay 1
+} -run
+
+# Two failures, one for obj3 and one for the attempt at sending error
+varnish v1 -expect SMA.Transient.c_fail == 2
+
+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