From b7f7faa0ec26f50251e520a2fad1825d0c4cbda0 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 2 Jan 2013 18:23:14 -0800 Subject: [PATCH] Fix race condition in stats flushing. Some threads are writing to the data buffer while we're trying to iterate over it. This will cause some lost stats, but no more than we're currently losing to the app dying when it hits the race condition. --- r2/r2/lib/stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/r2/r2/lib/stats.py b/r2/r2/lib/stats.py index 64d29a532..7f5aaef40 100644 --- a/r2/r2/lib/stats.py +++ b/r2/r2/lib/stats.py @@ -53,7 +53,8 @@ class TimingStatBuffer: def flush(self): """Yields accumulated timing and counter data and resets the buffer.""" data, self.data = self.data, collections.defaultdict(complex) - for k, v in data.iteritems(): + while data: + k, v = data.popitem() total_time, count = v.real, v.imag yield k, str(int(count)) + '|c' divisor = count or 1