Skip to content

Commit

Permalink
fix race where podman events exits to early
Browse files Browse the repository at this point in the history
In order to display all events we have to read until the event channel
is closed.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Sep 12, 2022
1 parent b3212a6 commit 2ae4ce7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cmd/podman/system/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {

for {
select {
case err := <-errChannel:
return err
case event := <-eventChannel:
case event, ok := <-eventChannel:
if !ok {
// channel was closed we can exit
return nil
}
switch {
case event == nil:
// no-op
case doJSON:
jsonStr, err := event.ToJSONString()
if err != nil {
Expand All @@ -121,6 +121,12 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
default:
fmt.Println(event.ToHumanReadable(!noTrunc))
}
case err := <-errChannel:
// only exit in case of an error,
// otherwise keep reading events until the event channel is closed
if err != nil {
return err
}
}
}
}
1 change: 1 addition & 0 deletions test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ load helpers
.*image tag $imageID $tag
.*image untag $imageID $tag:latest
.*image tag $imageID $tag
.*image untag $imageID $IMAGE
.*image untag $imageID $tag:latest
.*image remove $imageID $imageID" \
"podman events"
Expand Down

0 comments on commit 2ae4ce7

Please sign in to comment.