Commit 3e19f335 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Pål Hermunn Johansen

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
parent 8a8604da
...@@ -470,13 +470,13 @@ VSM_Init(void) ...@@ -470,13 +470,13 @@ VSM_Init(void)
problems with regard to readers on that event visible */ problems with regard to readers on that event visible */
vsl_segment_n = UINT_MAX - VSL_SEGMENTS + 1; vsl_segment_n = UINT_MAX - VSL_SEGMENTS + 1;
AZ(vsl_segment_n % VSL_SEGMENTS); AZ(vsl_segment_n % VSL_SEGMENTS);
vsl_head->segment_n = vsl_segment_n;
vsl_ptr = vsl_head->log; vsl_ptr = vsl_head->log;
*vsl_ptr = VSL_ENDMARKER; *vsl_ptr = VSL_ENDMARKER;
memset(vsl_head, 0, sizeof *vsl_head); memset(vsl_head, 0, sizeof *vsl_head);
vsl_head->segsize = vsl_segsize; vsl_head->segsize = vsl_segsize;
vsl_head->offset[0] = 0; vsl_head->offset[0] = 0;
vsl_head->segment_n = vsl_segment_n;
for (i = 1; i < VSL_SEGMENTS; i++) for (i = 1; i < VSL_SEGMENTS; i++)
vsl_head->offset[i] = -1; vsl_head->offset[i] = -1;
VWMB(); VWMB();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment