Skip to content

Ensure logs are flushed - #637

Merged
mrunalp merged 2 commits into
opencontainers:masterfrom
crosbymichael:flush-logs
Mar 15, 2016
Merged

mrunalp merged 2 commits into
opencontainers:masterfrom
crosbymichael:flush-logs

Conversation

@crosbymichael

Copy link
Copy Markdown
Member

This ensures that anything written to the logs are synced as they
happen.

This also changes the error message of the libcontainer error. The
original idea was to have this extra information in the message but it
makes it hard to parse and if the caller needed this information they
can just get it from the error type.

Signed-off-by: Michael Crosby [email protected]

Comment thread main.go Outdated
}
if path := context.GlobalString("log"); path != "" {
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|syscall.O_DSYNC, 0666)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we just use os.O_SYNC? Looks more consistent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks

This ensures that anything written to the logs are synced as they
happen.

This also changes the error message of the libcontainer error.  The
original idea was to have this extra information in the message but it
makes it hard to parse and if the caller needed this information they
can just get it from the error type.

Signed-off-by: Michael Crosby <[email protected]>
Because namespaces are being joined in the C init and because errors
reported during init are sent back to the parent process there is no
reason to do logging in the init as it cannot open the file on the host
side for `exec` anyways.

Signed-off-by: Michael Crosby <[email protected]>
@hqhq

hqhq commented Mar 15, 2016

Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@mrunalp

mrunalp commented Mar 15, 2016

Copy link
Copy Markdown
Contributor

LGTM

mrunalp pushed a commit that referenced this pull request Mar 15, 2016
@mrunalp
mrunalp merged commit 69fe79d into opencontainers:master Mar 15, 2016
@crosbymichael
crosbymichael deleted the flush-logs branch March 15, 2016 18:15
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
[Config Windows] Add anchor tags for headings
kolyshkin added a commit to kolyshkin/runc that referenced this pull request Oct 12, 2026
The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs
are flushed", PR opencontainers#637). The intent was to make sure log entries are not
lingering in a buffer, but *os.File is not buffered: logrus does a
single Write per entry, which is a single write(2), and the data is
visible to any reader (e.g. containerd reading the log after runc
exits) as soon as it returns.

What O_SYNC actually does is wait for the data to hit the disk on every
write, which only helps to preserve the log in case of a host crash or
power loss. This is of little value for runc logs, while the cost on a
slow disk (e.g. a network-attached cloud volume) is substantial,
especially with --debug.

Remove O_SYNC.

Fixes: opencontainers#5540
Suggested-by: Benjamin Peterson <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
lifubang pushed a commit to kolyshkin/runc that referenced this pull request Oct 20, 2026
The log file is opened with O_SYNC since commit 8f20692 ("Ensure logs
are flushed", PR opencontainers#637). The intent was to make sure log entries are not
lingering in a buffer, but *os.File is not buffered: logrus does a
single Write per entry, which is a single write(2), and the data is
visible to any reader (e.g. containerd reading the log after runc
exits) as soon as it returns.

What O_SYNC actually does is wait for the data to hit the disk on every
write, which only helps to preserve the log in case of a host crash or
power loss. This is of little value for runc logs, while the cost on a
slow disk (e.g. a network-attached cloud volume) is substantial,
especially with --debug.

Remove O_SYNC.

Fixes: opencontainers#5540
Suggested-by: Benjamin Peterson <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants