Skip to content

Commit 2062ab9

Browse files
Merge pull request #16072 from alexlarsson/events-shutdown-nosleep
libpod: Remove 100msec delay during shutdown
2 parents d33a315 + 5b71070 commit 2062ab9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

libpod/runtime.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,10 @@ func (r *Runtime) libimageEvents() {
722722

723723
eventChannel := r.libimageRuntime.EventChannel()
724724
go func() {
725+
sawShutdown := false
725726
for {
726727
// Make sure to read and write all events before
727-
// checking if we're about to shutdown.
728+
// shutting down.
728729
for len(eventChannel) > 0 {
729730
libimageEvent := <-eventChannel
730731
e := events.Event{
@@ -739,12 +740,15 @@ func (r *Runtime) libimageEvents() {
739740
}
740741
}
741742

742-
select {
743-
case <-r.libimageEventsShutdown:
743+
if sawShutdown {
744+
close(r.libimageEventsShutdown)
744745
return
746+
}
745747

746-
default:
747-
time.Sleep(100 * time.Millisecond)
748+
select {
749+
case <-r.libimageEventsShutdown:
750+
sawShutdown = true
751+
case <-time.After(100 * time.Millisecond):
748752
}
749753
}
750754
}()
@@ -793,7 +797,10 @@ func (r *Runtime) Shutdown(force bool) error {
793797
if r.store != nil {
794798
// Wait for the events to be written.
795799
if r.libimageEventsShutdown != nil {
800+
// Tell loop to shutdown
796801
r.libimageEventsShutdown <- true
802+
// Wait for close to signal shutdown
803+
<-r.libimageEventsShutdown
797804
}
798805

799806
// Note that the libimage runtime shuts down the store.

0 commit comments

Comments
 (0)