Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[18.09 backport] logger: fix follow logs for max-file=1 ENGCORE-1166 #377
Backport of moby#39969 to 18.09; clean cherry-pick, no issues. Original description follows.
In case jsonlogfile is used with
This situation is not handled by the log reader in follow mode,
This situation (file close/reopen) could be handled in
So, we have to handle this by checking the file size upon receiving
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
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 <firstname.lastname@example.org> (cherry picked from commit 9cd24ba) Signed-off-by: Kir Kolyshkin <email@example.com>