From 8eb5cf74892611f26c0c42c45312cb84e04882a2 Mon Sep 17 00:00:00 2001
From: Matthew Heon <matthew.heon@gmail.com>
Date: Mon, 19 Feb 2018 18:06:05 -0500
Subject: Ensure we don't repeatedly poll disk for exit codes

Change logic for refreshing our state using runc to only poll
for conmon exit files when we first transition to the Stopped
state. After that, we should already have the exit code stored in
the database, so we don't need to look it up again.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #363
Approved by: TomSweeneyRedHat
---
 libpod/oci.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'libpod')

diff --git a/libpod/oci.go b/libpod/oci.go
index 1fa85bda0..4847eceb6 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -308,6 +308,9 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string) (err e
 func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
 	state := new(spec.State)
 
+	// Store old state so we know if we were already stopped
+	oldState := ctr.state.State
+
 	out, err := exec.Command(r.path, "state", ctr.ID()).Output()
 	if err != nil {
 		return errors.Wrapf(err, "error getting container %s state. stderr/out: %s", ctr.ID(), out)
@@ -333,7 +336,9 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container) error {
 			ctr.ID(), state.Status)
 	}
 
-	if ctr.state.State == ContainerStateStopped {
+	// Only grab exit status if we were not already stopped
+	// If we were, it should already be in the database
+	if ctr.state.State == ContainerStateStopped && oldState != ContainerStateStopped {
 		exitFile := filepath.Join(r.exitsDir, ctr.ID())
 		var fi os.FileInfo
 		err = kwait.ExponentialBackoff(
-- 
cgit v1.2.3-54-g00ecf