-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
logger: fix follow logs for max-file=1 #39969
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>
Update: the above was mistakenly done using journald log driver :) Using |
|
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.
SGTM
should we have a test for this?
ah, I see your comment above; guess that means we can't add a test? |
@cpuguy83 ptal |
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.
LGTM
I think a test that's actually testing the problem would be rather difficult. |
In case jsonlogfile is used with
max-file=1
andmax-size
set,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_WRITE
in 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.EOF
from 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