Repository navigation
Ensure logs are flushed - #637
Merged
Merged
Conversation
| } | ||
| 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) |
Contributor
There was a problem hiding this comment.
Shall we just use os.O_SYNC? Looks more consistent.
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]>
crosbymichael
force-pushed
the
flush-logs
branch
from
March 14, 2016 18:20
5dfe4ad to
fa48b64
Compare
Contributor
|
LGTM |
1 similar comment
Contributor
|
LGTM |
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]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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]