[6.0] f97b73465 Don't change the C-L if we detect a failed stream.
Reza Naghibi
reza at naghibi.com
Tue Apr 20 18:31:05 UTC 2021
commit f97b7346522ec509d86ffbc3dcd2165eae48e1e4
Author: Reza Naghibi <reza at naghibi.com>
Date: Wed Mar 24 15:58:05 2021 -0400
Don't change the C-L if we detect a failed stream.
Previously we would read the response Content-Length from a failed oc,
which would make the error response valid. Now, if this is detected,
we don't touch the Content-Length.
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 30b6fdc0b..f24033ee1 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -409,7 +409,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
head = !strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD");
err = 0;
- if (boc != NULL)
+ if (boc != NULL || (req->objcore->flags & (OC_F_FAILED)))
req->resp_len = clval;
else
req->resp_len = ObjGetLen(req->wrk, req->objcore);
@@ -482,6 +482,11 @@ cnt_transmit(struct worker *wrk, struct req *req)
ObjSlim(wrk, req->objcore);
}
+ if (!req->doclose && (req->objcore->flags & OC_F_FAILED))
+ /* The object we delivered failed due to a streaming error.
+ * Fail the request. */
+ req->doclose = SC_TX_ERROR;
+
if (boc != NULL)
HSH_DerefBoc(wrk, req->objcore);
diff --git a/bin/varnishtest/tests/r03560.vtc b/bin/varnishtest/tests/r03560.vtc
new file mode 100644
index 000000000..fc76bbe1d
--- /dev/null
+++ b/bin/varnishtest/tests/r03560.vtc
@@ -0,0 +1,29 @@
+varnishtest "A backend connection error gets returned as a valid short response"
+
+barrier b1 sock 2
+
+server s1 {
+ rxreq
+ txresp -nolen -hdr "Content-Length: 10"
+ barrier b1 sync
+ send "12345"
+ # Early connection close error
+} -start
+
+varnish v1 -vcl+backend {
+ import vtc;
+
+ sub vcl_deliver {
+ # Make sure we are streaming and give the backend time to error out
+ vtc.barrier_sync("${b1_sock}");
+ vtc.sleep(1s);
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresphdrs
+ expect resp.http.Content-Length == "10"
+ recv 5
+ expect_close
+} -run
More information about the varnish-commit
mailing list