From b48d6d08efce4a8a1783eb9223954cd8e6f4de63 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Thu, 24 Feb 2022 17:29:59 +0800 Subject: [PATCH] [system-health] Fix file handle leak (#10059) - Why I did it swsscommon.ConfigDBConnector does not automatically close connection when the instance is recycled by python. So, it should not create this instance each time calling check_services. It will cause error like Failed to read from file /var/run/hw-management/led/led_status_capability - OSError(24, 'Too many open files') - How I did it Only connect DB once in init - How to verify it Manual test --- src/system-health/health_checker/service_checker.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/system-health/health_checker/service_checker.py b/src/system-health/health_checker/service_checker.py index 171f7e2e8b..b3c6fbc412 100644 --- a/src/system-health/health_checker/service_checker.py +++ b/src/system-health/health_checker/service_checker.py @@ -51,6 +51,8 @@ class ServiceChecker(HealthChecker): self.need_save_cache = False + self.config_db = None + self.load_critical_process_cache() def get_expected_running_containers(self, feature_table): @@ -248,9 +250,10 @@ class ServiceChecker(HealthChecker): Args: config (config.Config): Health checker configuration. """ - config_db = swsscommon.ConfigDBConnector() - config_db.connect() - feature_table = config_db.get_table("FEATURE") + if not self.config_db: + self.config_db = swsscommon.ConfigDBConnector() + self.config_db.connect() + feature_table = self.config_db.get_table("FEATURE") expected_running_containers, self.container_feature_dict = self.get_expected_running_containers(feature_table) current_running_containers = self.get_current_running_containers()