Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout to container.exec #574

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ def _update_cert(self):
# Repeat for the charm container.
ca_cert_path.unlink(missing_ok=True)

self.container.exec(["update-ca-certificates", "--fresh"]).wait()
subprocess.run(["update-ca-certificates", "--fresh"])
self.container.exec(["update-ca-certificates", "--fresh"], timeout=3).wait()
subprocess.run(["update-ca-certificates", "--fresh"], timeout=3)

def _configure(self, _):
"""Reconfigure and either reload or restart Prometheus.
Expand Down Expand Up @@ -779,7 +779,9 @@ def _promtool_check_config(self) -> tuple:
Returns:
A 2-tuple, (stdout, stderr).
"""
proc = self.container.exec(["/usr/bin/promtool", "check", "config", PROMETHEUS_CONFIG])
proc = self.container.exec(
["/usr/bin/promtool", "check", "config", PROMETHEUS_CONFIG], timeout=3
)
try:
output, err = proc.wait_output()
except ExecError as e:
Expand Down Expand Up @@ -1039,7 +1041,9 @@ def _prometheus_version(self) -> Optional[str]:
"""
if not self.container.can_connect():
return None
version_output, _ = self.container.exec(["/bin/prometheus", "--version"]).wait_output()
version_output, _ = self.container.exec(
["/bin/prometheus", "--version"], timeout=3
).wait_output()
# Output looks like this:
# prometheus, version 2.33.5 (branch: ...
result = re.search(r"version (\d*\.\d*\.\d*)", version_output)
Expand Down
Loading