Skip to content

Commit

Permalink
Merge pull request #16072 from alexlarsson/events-shutdown-nosleep
Browse files Browse the repository at this point in the history
libpod: Remove 100msec delay during shutdown
  • Loading branch information
openshift-merge-robot authored Oct 7, 2022
2 parents d33a315 + 5b71070 commit 2062ab9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,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{
Expand All @@ -739,12 +740,15 @@ func (r *Runtime) libimageEvents() {
}
}

select {
case <-r.libimageEventsShutdown:
if sawShutdown {
close(r.libimageEventsShutdown)
return
}

default:
time.Sleep(100 * time.Millisecond)
select {
case <-r.libimageEventsShutdown:
sawShutdown = true
case <-time.After(100 * time.Millisecond):
}
}
}()
Expand Down Expand Up @@ -793,7 +797,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.
Expand Down

0 comments on commit 2062ab9

Please sign in to comment.