From ce83d58b0afffaa3e0b9d57686c814a2b5fd771e Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Thu, 31 May 2018 23:58:01 +0300 Subject: [PATCH] [ledd] Use select() with timeout for AppDB notifications (#16) Otherwise ledd ignores signals other than SIGKILL making impossible to use __del__() destructors in LedClass implementations and delays pmon docker container shutdown up to 10s. Signed-off-by: Sergey Popovich --- sonic-ledd/scripts/ledd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sonic-ledd/scripts/ledd b/sonic-ledd/scripts/ledd index 8e813bea55..75a1d7e690 100644 --- a/sonic-ledd/scripts/ledd +++ b/sonic-ledd/scripts/ledd @@ -50,6 +50,8 @@ REDIS_HOSTNAME = "localhost" REDIS_PORT = 6379 REDIS_TIMEOUT_USECS = 0 +SELECT_TIMEOUT = 1000 + #========================== Syslog wrappers ========================== def log_info(msg): @@ -204,7 +206,13 @@ def main(): # Listen indefinitely for changes to the PORT table in the Application DB while True: - (state, c) = sel.select() + # Use timeout to prevent ignoring the signals we want to handle + # in signal_handler() (e.g. SIGTERM for graceful shutdown) + (state, c) = sel.select(SELECT_TIMEOUT) + + if state == swsscommon.Select.TIMEOUT: + # Do not flood log when select times out + continue if state != swsscommon.Select.OBJECT: log_warning("sel.select() did not return swsscommon.Select.OBJECT") continue