logger: fix follow logs for max-file=1#39969
Merged
cpuguy83 merged 1 commit intomoby:masterfrom Sep 23, 2019
Merged
Conversation
In case jsonlogfile is used with max-file=1 and max-size set, the log rotation is not perfomed; instead, the log file is closed and re-open with O_TRUNC. This situation is not handled by the log reader in follow mode, leading to an issue of log reader being stuck forever. This situation (file close/reopen) could be handled in waitRead(), but fsnotify library chose to not listen to or deliver this event (IN_CLOSE_WRITE in inotify lingo). So, we have to handle this by checking the file size upon receiving io.EOF from the log reader, and comparing the size with the one received earlier. In case the new size is less than the old one, the file was truncated and we need to seek to its beginning. Fixes moby#39235. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Contributor
Author
|
Update: the above was mistakenly done using journald log driver :) Using |
Contributor
Author
|
thaJeztah
approved these changes
Sep 21, 2019
Member
thaJeztah
left a comment
There was a problem hiding this comment.
SGTM
should we have a test for this?
Member
|
ah, I see your comment above; guess that means we can't add a test? |
Member
|
@cpuguy83 ptal |
Member
|
I think a test that's actually testing the problem would be rather difficult. |
This was referenced Sep 23, 2019
Merged
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.
In case jsonlogfile is used with
max-file=1andmax-sizeset,the log rotation is not performed; instead, the log file is closed
and re-opened with
O_TRUNC.This situation is not handled by the log reader in follow mode,
leading to an issue of log reader being stuck forever.
This situation (file close/reopen) could be handled in
waitRead(),but fsnotify library chose to not listen to or deliver this event
(
IN_CLOSE_WRITEin inotify lingo) as it's not portable,see fsnotify/fsnotify#252.
So, we have to handle this by checking the file size upon receiving
io.EOFfrom the log reader, and comparing the size with the one receivedearlier. In case the new size is less than the old one, the file was
truncated and we need to seek to its beginning.
Fixes #39235. See the steps to verify in that issue.
Description for the changelog
jsonfile logger: Fix lollow logs stuck when max-size is set and max-file=1