From d0faa75abaf6631f3b6919ed617850c78dd7c7e8 Mon Sep 17 00:00:00 2001 From: junchao Date: Tue, 22 Feb 2022 14:56:42 +0800 Subject: [PATCH] [system-health] Fix file handle leak --- 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 fa47e1e50c63..6918da0b9f0e 100644 --- a/src/system-health/health_checker/service_checker.py +++ b/src/system-health/health_checker/service_checker.py @@ -51,6 +51,8 @@ def __init__(self): 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 @@ def check_services(self, config): 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()