Skip to content

Commit

Permalink
use Popen communicate instead of wait
Browse files Browse the repository at this point in the history
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
  • Loading branch information
schmidax authored Mar 6, 2024
1 parent dd2a525 commit d8fa8ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/checkmk_kube_agent/send_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d8fa8ed

Please sign in to comment.