diff --git a/libpod/runtime.go b/libpod/runtime.go index be8398d21c..053c0c0f71 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -833,9 +833,10 @@ func (r *Runtime) libimageEvents() { eventChannel := r.libimageRuntime.EventChannel() go func() { + sawShutdown := false for { // Make sure to read and write all events before - // checking if we're about to shutdown. + // shutting down. for len(eventChannel) > 0 { libimageEvent := <-eventChannel e := events.Event{ @@ -850,12 +851,15 @@ func (r *Runtime) libimageEvents() { } } + if sawShutdown { + close(r.libimageEventsShutdown) + return + } + select { case <-r.libimageEventsShutdown: - return - - default: - time.Sleep(100 * time.Millisecond) + sawShutdown = true + case <-time.After(100 * time.Millisecond): } } }() @@ -904,7 +908,10 @@ func (r *Runtime) Shutdown(force bool) error { if r.store != nil { // Wait for the events to be written. if r.libimageEventsShutdown != nil { + // Tell loop to shutdown r.libimageEventsShutdown <- true + // Wait for close to signal shutdown + <-r.libimageEventsShutdown } // Note that the libimage runtime shuts down the store.