This to give predictable backend reuse behavior for varnishtest,
making the test cases non-racy.

Fixes: 1491
---
 bin/varnishd/cache/cache_fetch.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index dded999..32790cf 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -40,6 +40,23 @@
 #include "vtim.h"
 
 /*--------------------------------------------------------------------
+ * Release the VBC of the busyobj if still open
+ */
+static void
+vbf_release_vbc(struct busyobj *bo)
+{
+
+       CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+       if (bo->vbc != NULL) {
+               if (bo->should_close)
+                       VDI_CloseFd(&bo->vbc, &bo->acct);
+               else
+                       VDI_RecycleFd(&bo->vbc, &bo->acct);
+               AZ(bo->vbc);
+       }
+}
+
+/*--------------------------------------------------------------------
  * Allocate an object, with fall-back to Transient.
  * XXX: This somewhat overlaps the stuff in stevedore.c
  * XXX: Should this be merged over there ?
@@ -548,6 +565,11 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
                HSH_Unbusy(&wrk->stats, obj->objcore);
        }
        VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
+
+       /* Release the backend connection before setting BOS_FINISHED to
+          give predictable backend reuse behavior for varnishtest */
+       vbf_release_vbc(bo);
+
        VBO_setstate(bo, BOS_FINISHED);
        return (F_STP_DONE);
 }
@@ -639,6 +661,11 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
        assert(al == bo->ims_obj->len);
        assert(obj->len == al);
        EXP_Rearm(bo->ims_obj, bo->ims_obj->exp.t_origin, 0, 0, 0);
+
+       /* Release the backend connection before setting BOS_FINISHED to
+          give predictable backend reuse behavior for varnishtest */
+       vbf_release_vbc(bo);
+
        VBO_setstate(bo, BOS_FINISHED);
        VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
        return (F_STP_DONE);
@@ -789,13 +816,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 
        bo->stats = NULL;
 
-       if (bo->vbc != NULL) {
-               if (bo->should_close)
-                       VDI_CloseFd(&bo->vbc, &bo->acct);
-               else
-                       VDI_RecycleFd(&bo->vbc, &bo->acct);
-               AZ(bo->vbc);
-       }
+       vbf_release_vbc(bo);
 
        http_Teardown(bo->bereq);
        http_Teardown(bo->beresp);
-- 
1.9.2


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

Reply via email to