-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix several podman events issues #15717
Merged
+206
−127
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5bdb6a
fix hang with podman events file logger
Luap99 138b09c
event backend none: return an error when reading events
Luap99 76980a2
event backend journald: fix problem with empty journal
Luap99 cd32b92
libpod: runtime newEventer() cleanup
Luap99 72e715a
Use new secret store API
ashley-cui 12a1483
Improve --tmpdir and --events-backend docs
Luap99 b3212a6
set default EventsLogFilePath on first run
Luap99 2ae4ce7
fix race where podman events exits to early
Luap99 a63a40c
podman events --format: fix duplicated newline
Luap99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ Remote connections use local containers.conf for default. | |
#### **--events-backend**=*type* | ||
|
||
Backend to use for storing events. Allowed values are **file**, **journald**, and | ||
**none**. When *file* is specified, the events are stored under a subdirectory | ||
of the *tmpdir* location (see **--tmpdir** below). | ||
**none**. When *file* is specified, the events are stored under | ||
`<tmpdir>/events/events.log` (see **--tmpdir** below). | ||
|
||
#### **--help**, **-h** | ||
|
||
|
@@ -158,7 +158,7 @@ On remote clients, including Mac and Windows (excluding WSL2) machines, logging | |
|
||
#### **--tmpdir** | ||
|
||
Path to the tmp directory, for libpod runtime content. | ||
Path to the tmp directory, for libpod runtime content. Defaults to `$XDG\_RUNTIME\_DIR/libpod/tmp` as rootless and `run/libpod/tmp` as rootful. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
|
||
NOTE --tmpdir is not used for the temporary storage of downloaded images. Use the environment variable `TMPDIR` to change the temporary storage location of downloaded container images. Podman defaults to use `/var/tmp`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,57 +112,16 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { | |
} | ||
} | ||
|
||
// the api requires a next|prev before getting a cursor | ||
if _, err := j.Next(); err != nil { | ||
return fmt.Errorf("failed to move journal cursor to next entry: %w", err) | ||
} | ||
|
||
prevCursor, err := j.GetCursor() | ||
if err != nil { | ||
return fmt.Errorf("failed to get journal cursor: %w", err) | ||
} | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
// the consumer has cancelled | ||
return nil | ||
default: | ||
// fallthrough | ||
} | ||
|
||
if _, err := j.Next(); err != nil { | ||
return fmt.Errorf("failed to move journal cursor to next entry: %w", err) | ||
} | ||
newCursor, err := j.GetCursor() | ||
entry, err := getNextEntry(ctx, j, options.Stream, untilTime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: bug fix + refactor in the same commit is hard to review. |
||
if err != nil { | ||
return fmt.Errorf("failed to get journal cursor: %w", err) | ||
return err | ||
} | ||
if prevCursor == newCursor { | ||
if !options.Stream || (len(options.Until) > 0 && time.Now().After(untilTime)) { | ||
break | ||
} | ||
|
||
// j.Wait() is blocking, this would cause the goroutine to hang forever | ||
// if no more journal entries are generated and thus if the client | ||
// has closed the connection in the meantime to leak memory. | ||
// Waiting only 5 seconds makes sure we can check if the client closed in the | ||
// meantime at least every 5 seconds. | ||
t := 5 * time.Second | ||
if len(options.Until) > 0 { | ||
until := time.Until(untilTime) | ||
if until < t { | ||
t = until | ||
} | ||
} | ||
_ = j.Wait(t) | ||
continue | ||
// no entry == we hit the end | ||
if entry == nil { | ||
return nil | ||
} | ||
prevCursor = newCursor | ||
|
||
entry, err := j.GetEntry() | ||
if err != nil { | ||
return fmt.Errorf("failed to read journal entry: %w", err) | ||
} | ||
newEvent, err := newEventFromJournalEntry(entry) | ||
if err != nil { | ||
// We can't decode this event. | ||
|
@@ -177,7 +136,6 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { | |
options.EventChannel <- newEvent | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) { | ||
|
@@ -238,3 +196,51 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) { | |
func (e EventJournalD) String() string { | ||
return Journald.String() | ||
} | ||
|
||
// getNextEntry returns the next entry in the journal. If the end of the | ||
// journal is reached and stream is not set or the current time is after | ||
// the until time this function return nil,nil. | ||
func getNextEntry(ctx context.Context, j *sdjournal.Journal, stream bool, untilTime time.Time) (*sdjournal.JournalEntry, error) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
// the consumer has cancelled | ||
return nil, nil | ||
default: | ||
// fallthrough | ||
} | ||
// the api requires a next|prev before reading the event | ||
ret, err := j.Next() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to move journal cursor to next entry: %w", err) | ||
} | ||
// ret == 0 equals EOF, see sd_journal_next(3) | ||
if ret == 0 { | ||
if !stream || (!untilTime.IsZero() && time.Now().After(untilTime)) { | ||
// we hit the end and should not keep streaming | ||
return nil, nil | ||
} | ||
// keep waiting for the next entry | ||
// j.Wait() is blocking, this would cause the goroutine to hang forever | ||
// if no more journal entries are generated and thus if the client | ||
// has closed the connection in the meantime to leak memory. | ||
// Waiting only 5 seconds makes sure we can check if the client closed in the | ||
// meantime at least every 5 seconds. | ||
t := 5 * time.Second | ||
if !untilTime.IsZero() { | ||
until := time.Until(untilTime) | ||
if until < t { | ||
t = until | ||
} | ||
} | ||
_ = j.Wait(t) | ||
continue | ||
} | ||
|
||
entry, err := j.GetEntry() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read journal entry: %w", err) | ||
} | ||
return entry, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here look unrelated to the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not, for loop on event channel is blocking. Therefore we can never read the error channel.