summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-09-22 16:11:50 +0200
committerPaul Holzinger <pholzing@redhat.com>2021-09-22 17:40:16 +0200
commitdb44addf973671f3bbe420ebe1a63d01ef39d60c (patch)
tree62c5c09676d2a7842ac1c41216b0c73f495e5167 /libpod
parent8e2d25e93706190acf25bcf74bd18cdf98fb3a12 (diff)
downloadpodman-db44addf973671f3bbe420ebe1a63d01ef39d60c.tar.gz
podman-db44addf973671f3bbe420ebe1a63d01ef39d60c.tar.bz2
podman-db44addf973671f3bbe420ebe1a63d01ef39d60c.zip
sync container state before reading the healthcheck
The health check result is stored in the container state. Since the state can change or might not even be set we have to retrive the current state before we try to read the health check result. Fixes #11687 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_inspect.go2
-rw-r--r--libpod/healthcheck.go16
2 files changed, 12 insertions, 6 deletions
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index e65c86cef..42d8da52d 100644
--- a/libpod/container_inspect.go
+++ b/libpod/container_inspect.go
@@ -151,7 +151,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
if c.config.HealthCheckConfig != nil {
// This container has a healthcheck defined in it; we need to add it's state
- healthCheckState, err := c.GetHealthCheckLog()
+ healthCheckState, err := c.getHealthCheckLog()
if err != nil {
// An error here is not considered fatal; no health state will be displayed
logrus.Error(err)
diff --git a/libpod/healthcheck.go b/libpod/healthcheck.go
index c32ba85cb..91f031513 100644
--- a/libpod/healthcheck.go
+++ b/libpod/healthcheck.go
@@ -162,7 +162,7 @@ func newHealthCheckLog(start, end time.Time, exitCode int, log string) define.He
// updatedHealthCheckStatus updates the health status of the container
// in the healthcheck log
func (c *Container) updateHealthStatus(status string) error {
- healthCheck, err := c.GetHealthCheckLog()
+ healthCheck, err := c.getHealthCheckLog()
if err != nil {
return err
}
@@ -176,7 +176,7 @@ func (c *Container) updateHealthStatus(status string) error {
// UpdateHealthCheckLog parses the health check results and writes the log
func (c *Container) updateHealthCheckLog(hcl define.HealthCheckLog, inStartPeriod bool) error {
- healthCheck, err := c.GetHealthCheckLog()
+ healthCheck, err := c.getHealthCheckLog()
if err != nil {
return err
}
@@ -213,10 +213,11 @@ func (c *Container) healthCheckLogPath() string {
return filepath.Join(filepath.Dir(c.state.RunDir), "healthcheck.log")
}
-// GetHealthCheckLog returns HealthCheck results by reading the container's
+// getHealthCheckLog returns HealthCheck results by reading the container's
// health check log file. If the health check log file does not exist, then
// an empty healthcheck struct is returned
-func (c *Container) GetHealthCheckLog() (define.HealthCheckResults, error) {
+// The caller should lock the container before this function is called.
+func (c *Container) getHealthCheckLog() (define.HealthCheckResults, error) {
var healthCheck define.HealthCheckResults
if _, err := os.Stat(c.healthCheckLogPath()); os.IsNotExist(err) {
return healthCheck, nil
@@ -236,7 +237,12 @@ func (c *Container) HealthCheckStatus() (string, error) {
if !c.HasHealthCheck() {
return "", errors.Errorf("container %s has no defined healthcheck", c.ID())
}
- results, err := c.GetHealthCheckLog()
+ c.lock.Lock()
+ defer c.lock.Unlock()
+ if err := c.syncContainer(); err != nil {
+ return "", err
+ }
+ results, err := c.getHealthCheckLog()
if err != nil {
return "", errors.Wrapf(err, "unable to get healthcheck log for %s", c.ID())
}