mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user