Skip to content

journald logs: drain 1 more time at container exit - #29863

Merged
LK4D4 merged 1 commit into
moby:masterfrom
ncdc:journald-logdriver-drain-one-more-time-after-follow-ends
Feb 1, 2017
Merged

LK4D4 merged 1 commit into
moby:masterfrom
ncdc:journald-logdriver-drain-one-more-time-after-follow-ends

Conversation

@ncdc

@ncdc ncdc commented Jan 3, 2017

Copy link
Copy Markdown
Contributor

- What I did
In the journald log driver, try to retrieve container log entries that appear immediately prior to the container exiting.

- How I did it
Attempt to drain the journal 1 more time after being told to stop following the log. Due to a possible race condition, sometimes data is written to the journal at almost the same time the log watch is closed, and depending on the order of operations, sometimes you miss the last journal entry.

- How to verify it

  1. Start docker using the journald log driver
  2. docker rm foo
  3. docker create --name foo centos:centos7 sh -c 'echo a; sleep 1; echo b; sleep 1; echo c' && docker start foo && docker logs -f foo
  4. You will frequently not see the last line (c)

- Description for the changelog

journald log driver: try to retrieve log entries emitted just prior to container termination when following a container's log

@runcom @nalind @jwhonce

@tonistiigi

tonistiigi commented Jan 5, 2017 •

Copy link
Copy Markdown
Member

@ncdc It looks like it might be more readable if we would always try to get status before draining inside the loop. Atm there are 2 calls to wait and 2 calls to drain.

@ncdc

ncdc commented Jan 6, 2017

Copy link
Copy Markdown
Contributor Author

@tonistiigi I think there always need to be 2 calls to drain: 1 inside the loop, and 1 outside after the loop exits. If c.wait_for_data_cancelable returns something other than 1 inside the loop, it means that either <-logWatcher.WatchClose() fired, or there was an error waiting for more data from the journal. Assuming it's the former, we still need to call drain 1 more time to try to get any data written to the journal immediately prior to the container exiting and the tail stopping. Did you have a way to still do that but make this cleaner?

@tonistiigi

Copy link
Copy Markdown
Member

@ncdc Yeah, I might be missing something. This is what I had in mind:

for {
  status = C.wait_for_data_cancelable(j, pfd[0])
  if status < 0 {
    // break error
  }
  drain()
  if status != 1 {
   break
  }
}

@ncdc

ncdc commented Jan 6, 2017

Copy link
Copy Markdown
Contributor Author

That definitely looks nicer. @nalind wdyt?

@nalind

nalind commented Jan 25, 2017

Copy link
Copy Markdown
Contributor

It's still a race, as you noted, but this can't hurt.

In the journald log driver, attempt to drain the journal 1 more time
after being told to stop following the log. Due to a possible race
condition, sometimes data is written to the journal at almost the same
time the log watch is closed, and depending on the order of operations,
sometimes you miss the last journal entry.

Signed-off-by: Andy Goldstein <[email protected]>
@ncdc
ncdc force-pushed the journald-logdriver-drain-one-more-time-after-follow-ends branch from 15d70bc to 76f58d7 Compare January 25, 2017 14:30
@ncdc

ncdc commented Jan 25, 2017

Copy link
Copy Markdown
Contributor Author

@tonistiigi @nalind updated, ptal

@tonistiigi

Copy link
Copy Markdown
Member

LGTM

1 similar comment
@runcom

runcom commented Jan 25, 2017

Copy link
Copy Markdown
Member

LGTM

@LK4D4 LK4D4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@LK4D4
LK4D4 merged commit dc78b3a into moby:master Feb 1, 2017
@GordonTheTurtle GordonTheTurtle added this to the 1.14.0 milestone Feb 1, 2017
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