From 60578f90fba5d7c0224bfa99c4c42cd200a23ef8 Mon Sep 17 00:00:00 2001 From: Jiri Konecny Date: Tue, 15 Oct 2024 16:15:50 +0200 Subject: [PATCH] Suppress tracebacks when SIGTERM signal processing This is a workaround for https://github.com/rhinstaller/kickstart-tests/issues/1296 where we are most likely hitting issue that logging is not safe to use in the signal handlers because logging is not reentrant safe. To avoid failures in KS tests and also test if this is the correct issue, let's use this workaround. The ideal fix should be to not use logging in atexit call which might be tricky to resolve and also we will use a lot of log outputs. --- anaconda.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/anaconda.py b/anaconda.py index b54726119be..acc0e1525d1 100755 --- a/anaconda.py +++ b/anaconda.py @@ -289,9 +289,18 @@ def setup_environment(): from pyanaconda.anaconda import Anaconda anaconda = Anaconda() + def terminate(num, frame): + try: + # This will execute atexit function which might fail because of logging exception + # which shouldn't be used in signal handlers. However, it's during the shutdown + # process so let's suppress this to avoid issues. + sys.exit(1) + except Exception as ex: + print("Error raised when terminating Anaconda: \n %s", ex) + # reset python's default SIGINT handler signal.signal(signal.SIGINT, signal.SIG_IGN) - signal.signal(signal.SIGTERM, lambda num, frame: sys.exit(1)) + signal.signal(signal.SIGTERM, terminate) # synchronously-delivered signals such as SIGSEGV and SIGILL cannot be handled properly from # Python, so install signal handlers from the faulthandler stdlib module.