Skip to content

Commit 3bf8b6f

Browse files
committed
Ensure signal handler does not run concurrently
Currently, a signal handler may be invoked while another one is running. This resulted in a race when two concurrent python functions attempted to read from and write to the same file. This commit fixes #174.
1 parent cb6ea7f commit 3bf8b6f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/run_printer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
DUMP_SIGNAL = signal.SIGUSR1
3737
_DUMPED_RUN = "dumped-run.json"
3838

39+
_SIGNAL_HANDLER_RUNNING = False
40+
3941

4042
def add_subparser(subparsers):
4143
dump_run_pars = subparsers.add_parser("dump-run")
@@ -206,7 +208,14 @@ class DumpRunSignalHandler:
206208

207209

208210
def __call__(self, _signum, _frame):
211+
global _SIGNAL_HANDLER_RUNNING
212+
213+
if _SIGNAL_HANDLER_RUNNING:
214+
return
215+
216+
_SIGNAL_HANDLER_RUNNING = True
209217
run = lib.litani_report.get_run_data(self.cache_dir)
210218
with lib.litani.atomic_write(
211219
self.cache_dir / _DUMPED_RUN) as handle:
212220
print(json.dumps(run, indent=2), file=handle)
221+
_SIGNAL_HANDLER_RUNNING = False

0 commit comments

Comments
 (0)