[4.1] 0b0bf92 Make sure that VFP_Close is always called if and only if VFP_Open was called

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Fri Aug 12 11:36:09 CEST 2016

commit 0b0bf921f065ff746f38ff2c598f338f67f2cb02
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu May 19 16:06:20 2016 +0200

    Make sure that VFP_Close is always called if and only if VFP_Open was called
    For some (out of workspace or stevedore allocationi failure) errors
    VFP_Close would fail to be called when ending up not retrying the
    fetch. This would then potentially leak VFP entry context data like
    gzip buffers. Fix this by always calling VFP_Close() when changing
    fetch state when VFP_Open() has been called.
    Also VFP_Close() would for some retries be called twice, causing
    double accounting log records print out. This happens when a late
    error is caught and streaming is disabled, allowing a retry to be
    attempted. Fix this by not unconditionally calling VFP_Close() in the
    error state.

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 880fb4e..8a133dd 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -234,8 +234,6 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
 	bo->do_stream = 1;
 	/* reset fetch processors */
-	vfc->failed = 0;
-	VFP_Close(vfc);
 	// XXX: BereqEnd + BereqAcct ?
@@ -632,6 +630,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	if (vbf_beresp2obj(bo)) {
 		(void)VFP_Error(bo->vfc, "Could not get storage");
 		bo->htc->doclose = SC_RX_BODY;
+		VFP_Close(bo->vfc);
 		VDI_Finish(bo->wrk, bo);
 		return (F_STP_ERROR);
@@ -655,6 +654,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	    VDI_GetBody(bo->wrk, bo) != 0) {
 		    "GetBody failed - backend_workspace overflow?");
+		VFP_Close(bo->vfc);
 		bo->htc->doclose = SC_OVERLOAD;
 		VDI_Finish(bo->wrk, bo);
 		return (F_STP_ERROR);

More information about the varnish-commit mailing list