Commit 0d93605b authored by Brenden Blanco's avatar Brenden Blanco

Avoid infinite loops in BPF.Table destructor

In the case that python process tries to clear() a table object while
the bpf program is still running and doing lookup_or_init, the python
clean() routine will race with the bpf program (and bpf will win in the
case of frequent kprobe hits) causing a hang. Instead, first get the
full list of keys and then delete them rather than rely on the default
popitem implementation.

Fixes: #233
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 14915e05
......@@ -223,14 +223,9 @@ class BPF(object):
raise KeyError
def clear(self):
if self.ttype in (BPF.ARRAY, BPF.PROG_ARRAY):
# Special case clear, since this class is currently behaving
# like a dict but popitem on an array causes an infinite loop.
# TODO: derive Table from array.array instead
for k in self.keys():
self.__delitem__(k)
else:
super(BPF.Table, self).clear()
# default clear uses popitem, which can race with the bpf prog
for k in self.keys():
self.__delitem__(k)
@staticmethod
def _stars(val, val_max, width):
......
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