[master] 717f0fb Spotted while looking for 1449:

Poul-Henning Kamp phk at FreeBSD.org
Thu Mar 13 16:03:25 CET 2014


commit 717f0fb9995b25ebead1549f32ebd06e65fe7da7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Mar 13 15:02:43 2014 +0000

    Spotted while looking for 1449:
    
    Make sure we do not send a regular "end-chunk" to the
    client if the streaming fetch fails.

diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index 5a3da11..231df94 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -157,7 +157,7 @@ v1d_dorange(struct req *req, const char *r)
 
 /*--------------------------------------------------------------------*/
 
-static void
+static enum objiter_status
 v1d_WriteDirObj(struct req *req)
 {
 	enum objiter_status ois;
@@ -190,12 +190,14 @@ v1d_WriteDirObj(struct req *req)
 	} while (ois == OIS_DATA || ois == OIS_STREAM);
 	(void)VDP_bytes(req, VDP_FINISH,  NULL, 0);
 	ObjIterEnd(&oi);
+	return (ois);
 }
 
 void
 V1D_Deliver(struct req *req)
 {
 	char *r;
+	enum objiter_status ois;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
@@ -291,6 +293,7 @@ V1D_Deliver(struct req *req)
 	if (req->res_mode & RES_CHUNKED)
 		WRW_Chunked(req->wrk);
 
+	ois = OIS_DONE;
 	if (!req->wantbody) {
 		/* This was a HEAD or conditional request */
 	} else if (req->res_mode & RES_ESI) {
@@ -305,17 +308,19 @@ V1D_Deliver(struct req *req)
 		VDP_push(req, VDP_gunzip);
 		req->vgz = VGZ_NewUngzip(req->vsl, "U D -");
 		AZ(VGZ_WrwInit(req->vgz));
-		v1d_WriteDirObj(req);
+		ois = v1d_WriteDirObj(req);
 		(void)VGZ_Destroy(&req->vgz);
 		VDP_pop(req, VDP_gunzip);
 	} else {
-		v1d_WriteDirObj(req);
+		ois = v1d_WriteDirObj(req);
 	}
 
-	if (req->res_mode & RES_CHUNKED && !(req->res_mode & RES_ESI_CHILD))
+	if (ois == OIS_DONE &&
+	    (req->res_mode & RES_CHUNKED) &&
+	    !(req->res_mode & RES_ESI_CHILD))
 		WRW_EndChunk(req->wrk);
 
-	if (WRW_FlushRelease(req->wrk) && req->sp->fd >= 0)
+	if ((WRW_FlushRelease(req->wrk) || ois != OIS_DONE) && req->sp->fd >= 0)
 		SES_Close(req->sp, SC_REM_CLOSE);
 }
 
diff --git a/bin/varnishtest/tests/c00062.vtc b/bin/varnishtest/tests/c00062.vtc
new file mode 100644
index 0000000..643a2f6
--- /dev/null
+++ b/bin/varnishtest/tests/c00062.vtc
@@ -0,0 +1,29 @@
+varnishtest "Check that aborted backend body aborts client in streaming mode"
+
+server s1 {
+	rxreq
+	txresp -nolen -hdr "Transfer-encoding: chunked"
+	chunked {<HTML>}
+	sema r1 sync 2
+	chunked {<HTML>}
+	sema r1 sync 2
+} -start
+
+varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend {
+
+} -start
+
+
+client c1 {
+	txreq
+	rxresphdrs
+	expect resp.status == 200
+	rxchunk
+	sema r1 sync 2
+	rxchunk
+	sema r1 sync 2
+	expect_close
+} -run
+
+
+
diff --git a/bin/varnishtest/tests/r01086.vtc b/bin/varnishtest/tests/r01086.vtc
index 667cc4d..d861a0d 100644
--- a/bin/varnishtest/tests/r01086.vtc
+++ b/bin/varnishtest/tests/r01086.vtc
@@ -65,9 +65,9 @@ varnish v1 -vcl+backend {
 
 client c1 {
 	txreq -hdr "Cookie: FOO"
-	rxresp
+	rxresphdrs
 	expect resp.status == 200
-	expect resp.bodylen == 0
+	expect_close
 } -run
 
 delay .1



More information about the varnish-commit mailing list