From d8fa8ed06984a3e6cb601dc59286a8ef8be4b616 Mon Sep 17 00:00:00 2001 From: schmidax <64590250+schmidax@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:05:15 +0100 Subject: [PATCH] use Popen communicate instead of wait Like described in this (https://stackoverflow.com/a/39477247) stackoverflow comment, it is not a good idea to use wait, because it can andup in a deadlock. This can also fix the problem in this issue https://forum.checkmk.com/t/checkmk-k8s-node-metrics-collector/43278 --- src/checkmk_kube_agent/send_metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkmk_kube_agent/send_metrics.py b/src/checkmk_kube_agent/send_metrics.py index 5a64088..9ef47c8 100644 --- a/src/checkmk_kube_agent/send_metrics.py +++ b/src/checkmk_kube_agent/send_metrics.py @@ -373,14 +373,14 @@ def machine_sections_worker( ["/usr/local/bin/check_mk_agent"], stdout=subprocess.PIPE, ) as process: - returncode = process.wait(5) + (out, err) = process.communicate(timeout=5) if returncode != 0: # we don't capture stderr so it's printed to stderr of this process # and hopefully contains a helpful error message... raise RuntimeError("Agent execution failed.") if process.stdout is None: raise RuntimeError("Could not read agent output") - sections = process.stdout.read().decode("utf-8") + sections = out.decode("utf-8") logger.info("Parsing and sending machine sections") cluster_collector_response = session.post(