Skip to content

Commit

Permalink
python: Grab all keys before zeroing
Browse files Browse the repository at this point in the history
To avoid a potential race with the key zeroing modifying
the next hash key retrieved by the loop in `Table.zero()`,
retrieve all the keys in user space first before starting
the zeroing loop. See discussion on iovisor#780.

Tested with `funccount 'SyS_*' -i 1` while running a heavy
read/write test application (`dd`) in the background for
several minutes with no visible issues.
  • Loading branch information
goldshtn committed Oct 25, 2016
1 parent dd7ec5a commit 6031ccb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/python/bcc/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ def clear(self):
self.__delitem__(k)

def zero(self):
for k in self.keys():
# Even though this is not very efficient, we grab the entire list of
# keys before enumerating it. This helps avoid a potential race where
# the leaf assignment changes a hash table bucket that is being
# enumerated by the same loop, and may lead to a hang.
for k in list(self.keys()):
self[k] = self.Leaf()

def __iter__(self):
Expand Down

0 comments on commit 6031ccb

Please sign in to comment.