Skip to content

Comments

Fix issues with tailing rotated jsonlog file#24514

Merged
aaronlehmann merged 1 commit intomoby:masterfrom
cpuguy83:fix_log_follow_rotate
Aug 26, 2016
Merged

Fix issues with tailing rotated jsonlog file#24514
aaronlehmann merged 1 commit intomoby:masterfrom
cpuguy83:fix_log_follow_rotate

Conversation

@cpuguy83
Copy link
Member

@cpuguy83 cpuguy83 commented Jul 11, 2016

Fixes a race where the log reader would get events for both an actual
rotation and from fsnotify (fsnotify.Rename).
This issue becomes extremely apparent when rotations are fast, for
example:

$ docker run -d --name test --log-opt max-size=1 --log-opt max-file=2
busybox sh -c 'while true; do echo hello; usleep 100000; done'

With this change the log reader for jsonlogs can handle rotations that
happen as above.

Instead of listening for both fs events AND rotation events
simultaneously, potentially meaning we see 2 rotations for only a single
rotation due to channel buffering, only listen for fs events (like
Rename) and then wait to be notified about rotation by the logger.
This makes sure that we don't see 2 rotations for 1, and that we don't
start trying to read until the logger is actually ready for us to.

Fixes #21220
Fixes #23913

@paralin
Copy link

paralin commented Jul 23, 2016

+1, fixed the issue for me on ARM64.

@cpuguy83 cpuguy83 added this to the 1.13.0 milestone Jul 29, 2016
@LK4D4
Copy link
Contributor

LK4D4 commented Aug 4, 2016

LGTM

@paralin
Copy link

paralin commented Aug 13, 2016

Can this get merged?

@thaJeztah
Copy link
Member

ping @tonistiigi @aaronlehmann PTAL

Choose a reason for hiding this comment

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

"...due to rotations..."

Fixes a race where the log reader would get events for both an actual
rotation as we from fsnotify (`fsnotify.Rename`).
This issue becomes extremely apparent when rotations are fast, for
example:

```
$ docker run -d --name test --log-opt max-size=1 --log-opt max-file=2
busybox sh -c 'while true; do echo hello; usleep 100000; done'
```

With this change the log reader for jsonlogs can handle rotations that
happen as above.

Instead of listening for both fs events AND rotation events
simultaneously, potentially meaning we see 2 rotations for only a single
rotation due to channel buffering, only listen for fs events (like
`Rename`) and then wait to be notified about rotation by the logger.
This makes sure that we don't see 2 rotations for 1, and that we don't
start trying to read until the logger is actually ready for us to.

Signed-off-by: Brian Goff <[email protected]>
@cpuguy83 cpuguy83 force-pushed the fix_log_follow_rotate branch from 8d6f2e3 to 84e60a7 Compare August 15, 2016 17:57
@cpuguy83
Copy link
Member Author

ping @aaronlehmann

@aaronlehmann
Copy link

LGTM

@suchisubhra
Copy link

I am having same problem.. I am user master tag. is it available in master tag?

@cpuguy83 cpuguy83 deleted the fix_log_follow_rotate branch November 4, 2016 20:44
@cpuguy83
Copy link
Member Author

cpuguy83 commented Nov 4, 2016

@suchisubhra Yes, it is in master.
If you are experiencing a problem, please open an new issue with the details.

Thanks!

liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
Fixes a race where the log reader would get events for both an actual
rotation as we from fsnotify (`fsnotify.Rename`).
This issue becomes extremely apparent when rotations are fast, for
example:

```
$ docker run -d --name test --log-opt max-size=1 --log-opt max-file=2
busybox sh -c 'while true; do echo hello; usleep 100000; done'
```

With this change the log reader for jsonlogs can handle rotations that
happen as above.

Instead of listening for both fs events AND rotation events
simultaneously, potentially meaning we see 2 rotations for only a single
rotation due to channel buffering, only listen for fs events (like
`Rename`) and then wait to be notified about rotation by the logger.
This makes sure that we don't see 2 rotations for 1, and that we don't
start trying to read until the logger is actually ready for us to.

backport from moby#24514
conflict:
	daemon/logger/jsonfilelog/read.go

Signed-off-by: Brian Goff <[email protected]>
Signed-off-by: Yuanhong Peng <[email protected]>
liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
Fix issues with tailing rotated jsonlog file

Fixes a race where the log reader would get events for both an actual
rotation as we from fsnotify (`fsnotify.Rename`).
This issue becomes extremely apparent when rotations are fast, for
example:

```
$ docker run -d --name test --log-opt max-size=1 --log-opt max-file=2
busybox sh -c 'while true; do echo hello; usleep 100000; done'
```

With this change the log reader for jsonlogs can handle rotations that
happen as above.

Instead of listening for both fs events AND rotation events
simultaneously, potentially meaning we see 2 rotations for only a single
rotation due to channel buffering, only listen for fs events (like
`Rename`) and then wait to be notified about rotation by the logger.
This makes sure that we don't see 2 rotations for 1, and that we don't
start trying to read until the logger is actually ready for us to.

backport from moby#24514
conflict:
	daemon/logger/jsonfilelog/read.go

Signed-off-by: Brian Goff <[email protected]>
Signed-off-by: Yuanhong Peng <[email protected]>



See merge request docker/docker!592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants