diff options
author | Arthur de Kerhor <arthurdekerhor@gmail.com> | 2021-06-24 19:39:44 +0200 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2021-06-25 01:04:16 +0000 |
commit | c9ae8cfaccd75fbc2dc27bdebccdbd14fc0cb60c (patch) | |
tree | a0e07ebfa77b767b806156b882d6529c89ee367d /src/vpp-api | |
parent | 806709fc7c3209f8afaf31b3fc388b127c99fba5 (diff) |
stats: fix race conditions in vpp-api stats client
Type: fix
Signed-off-by: Arthur de Kerhor <arthurdekerhor@gmail.com>
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Change-Id: Ie5c197f6ec0d41d5e405b22662701d83ad94d29e
Diffstat (limited to 'src/vpp-api')
-rwxr-xr-x | src/vpp-api/python/vpp_papi/vpp_stats.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py index 884a30019f8..b407b56a85f 100755 --- a/src/vpp-api/python/vpp_papi/vpp_stats.py +++ b/src/vpp-api/python/vpp_papi/vpp_stats.py @@ -187,12 +187,12 @@ class VPPStats(): while True: try: with self.lock: + self.last_epoch = self.epoch for i, direntry in enumerate(StatsVector(self, self.directory_vector, self.elementfmt)): path_raw = direntry[2].find(b'\x00') path = direntry[2][:path_raw].decode('ascii') directory[path] = StatsEntry(direntry[0], direntry[1]) directory_by_idx[i] = path - self.last_epoch = self.epoch self.directory = directory self.directory_by_idx = directory_by_idx @@ -200,7 +200,9 @@ class VPPStats(): self.error_vectors = [] for threads in StatsVector(self, self.error_vector, 'P'): self.error_vectors.append(StatsVector(self, threads[0], 'Q')) - return + # Return statement must be outside the lock block to be sure + # lock.release is executed + return except IOError: if not blocking: raise @@ -213,7 +215,10 @@ class VPPStats(): if self.last_epoch != self.epoch: self.refresh(blocking) with self.lock: - return self.directory[item].get_counter(self) + result = self.directory[item].get_counter(self) + # Return statement must be outside the lock block to be sure + # lock.release is executed + return result except IOError: if not blocking: raise @@ -267,7 +272,10 @@ class VPPStats(): if self.last_epoch != self.epoch: self.refresh(blocking) with self.lock: - return sum(self.directory[name].get_counter(self)) + result = sum(self.directory[name].get_counter(self)) + # Return statement must be outside the lock block to be sure + # lock.release is executed + return result except IOError: if not blocking: raise |