[4.1] 3e19f33 Fix race in the VSL segment counter initialization

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Tue Apr 4 17:10:07 CEST 2017


commit 3e19f335e78e8100ae0eb3c9ddc0d4f14c389430
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Mar 7 17:13:26 2017 +0100

    Fix race in the VSL segment counter initialization
    
    Fix a stupid misstake where the segment counter in the VSL segment was
    set just before the entire struct was cleared during
    initialization. This didn't cause problems in the common case because
    it would be set correctly on the very first log line produced. But it
    did open a race where an unfortunate early log client would assume it
    was lagging indefinetely behind varnishd on the log reading and report
    overflow error. This was most commonly experienced with varnishtest.
    
    Fixes: #2241

diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 789e902..b96bf73 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -470,13 +470,13 @@ VSM_Init(void)
 	   problems with regard to readers on that event visible */
 	vsl_segment_n = UINT_MAX - VSL_SEGMENTS + 1;
 	AZ(vsl_segment_n % VSL_SEGMENTS);
-	vsl_head->segment_n = vsl_segment_n;
 	vsl_ptr = vsl_head->log;
 	*vsl_ptr = VSL_ENDMARKER;
 
 	memset(vsl_head, 0, sizeof *vsl_head);
 	vsl_head->segsize = vsl_segsize;
 	vsl_head->offset[0] = 0;
+	vsl_head->segment_n = vsl_segment_n;
 	for (i = 1; i < VSL_SEGMENTS; i++)
 		vsl_head->offset[i] = -1;
 	VWMB();



More information about the varnish-commit mailing list