Skip to content
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

[18.09 backport] logger: fix follow logs for max-file=1 ENGCORE-1166 #377

Merged

Conversation

@kolyshkin
Copy link

kolyshkin commented Sep 23, 2019

Backport of moby#39969 to 18.09; clean cherry-pick, no issues. Original description follows.


In case jsonlogfile is used with max-file=1 and max-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 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. 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

ENGCORE-1166

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>
(cherry picked from commit 9cd24ba)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin added this to the 18.09.10 milestone Sep 23, 2019
Copy link
Member

thaJeztah left a comment

LGTM

@thaJeztah thaJeztah merged commit e34d52d into docker:18.09 Sep 26, 2019
1 check passed
1 check passed
continuous-integration/jenkins/pr-merge This commit looks good
Details
@andrewhsu andrewhsu changed the title [18.09 backport] logger: fix follow logs for max-file=1 [18.09 backport] logger: fix follow logs for max-file=1 ENGCORE-1166 Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.