Fixes: #1140
---
 bin/varnishd/cache/cache_center.c |    4 ++--
 bin/varnishtest/tests/r01140.vtc  |   31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 bin/varnishtest/tests/r01140.vtc

diff --git a/bin/varnishd/cache/cache_center.c 
b/bin/varnishd/cache/cache_center.c
index 335bda7..5344467 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -813,12 +813,12 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct 
req *req)
                 * Try to salvage the transaction by allocating a
                 * shortlived object on Transient storage.
                 */
-               req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE,
-                   l, nhttp);
                if (bo->exp.ttl > cache_param->shortlived)
                        bo->exp.ttl = cache_param->shortlived;
                bo->exp.grace = 0.0;
                bo->exp.keep = 0.0;
+               req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE,
+                   l, nhttp);
        }
        bo->stats = NULL;
        if (req->obj == NULL) {
diff --git a/bin/varnishtest/tests/r01140.vtc b/bin/varnishtest/tests/r01140.vtc
new file mode 100644
index 0000000..483e0d6
--- /dev/null
+++ b/bin/varnishtest/tests/r01140.vtc
@@ -0,0 +1,31 @@
+varnishtest "Transient-salvaged objects ttl should be shortened - #1140"
+
+server s1 {
+       # This response should almost completely fill the storage
+       rxreq
+       txresp -bodylen 1048050
+       # The next one should not fit in the storage, ending up in transient
+       rxreq
+       txresp -bodylen 1024
+} -start
+
+varnish v1 -arg "-p expiry_sleep=0.01 -p nuke_limit=0 -p shortlived=1" 
-storage "-smalloc,1m" -vcl+backend {
+} -start
+
+client c1 {
+       txreq -url /url1
+       rxresp
+       expect resp.status == 200
+       expect resp.bodylen == 1048050
+
+       txreq -url /url2
+       rxresp
+       expect resp.status == 200
+       expect resp.bodylen == 1024
+} -run
+
+varnish v1 -expect SMA.Transient.g_bytes != 0
+
+delay 1.5
+
+varnish v1 -expect SMA.Transient.g_bytes == 0
-- 
1.7.9.5


_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to