Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

[19.03 backport] logger: fix follow logs for max-file=1 ENGCORE-1165 #378

Merged

Conversation

kolyshkin
Copy link

@kolyshkin kolyshkin commented Sep 23, 2019

Backport of moby#39969 to 19.03; 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-1165

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

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit cf298d3 into docker-archive:19.03 Sep 24, 2019
@andrewhsu andrewhsu changed the title [19.03 backport] logger: fix follow logs for max-file=1 [19.03 backport] logger: fix follow logs for max-file=1 ENGCORE-1165 Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants