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

Bugfix: Use local JSON log buffer in parseDockerJSONLog. #50381

Merged
merged 1 commit into from
Sep 1, 2017
Merged

Bugfix: Use local JSON log buffer in parseDockerJSONLog. #50381

merged 1 commit into from
Sep 1, 2017

Conversation

sczizzo
Copy link

@sczizzo sczizzo commented Aug 9, 2017

What this PR does / why we need it:
The issue described in #47800 is due to a race condition in ReadLogs: Because the JSON log buffer (dockerJSONLog) is package-scoped, any two goroutines modifying the buffer could race and overwrite the other's changes. In particular, one goroutine could unmarshal a JSON log line into the buffer, then another goroutine could Reset() the buffer, and the resulting Stream would be empty (""). This empty Stream is caught in a case block and raises an unexpected stream type error.

This PR creates a new buffer for each execution of parseDockerJSONLog, so each goroutine is guaranteed to have a local instance of the buffer.

Which issue this PR fixes: fixes #47800

Release note:

Fixed an issue (#47800) where `kubectl logs -f` failed with `unexpected stream type ""`.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 9, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @sczizzo. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 9, 2017
@k8s-github-robot k8s-github-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 9, 2017
@dims
Copy link
Member

dims commented Aug 9, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 9, 2017
@sczizzo
Copy link
Author

sczizzo commented Aug 9, 2017

/test pull-kubernetes-e2e-gce-etcd3

@thockin
Copy link
Member

thockin commented Aug 10, 2017

This seems horribly broken to start with, which makes me suspicious of whether something deeper is happening.

@Random-Liu ?

@thockin thockin assigned Random-Liu and unassigned thockin Aug 10, 2017
@smarterclayton
Copy link
Contributor

@derekwaynecarr

@feiskyer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 29, 2017
@feiskyer
Copy link
Member

/cc @Random-Liu

Copy link
Member

@Random-Liu Random-Liu left a comment

Choose a reason for hiding this comment

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

Sorry for the stupid bug. Don't know what I was thinking at that time...
@sczizzo Thanks for the fix!

dockerJSONLog.Reset()
l := dockerJSONLog
var l = &jsonlog.JSONLog{}
l.Reset()
Copy link
Member

Choose a reason for hiding this comment

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

The reset is not needed then.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sczizzo could you fix this? Thanks!

@yujuhong
Copy link
Contributor

We should cherry-pick this to 1.7 and 1.6.

@yujuhong yujuhong added this to the v1.7 milestone Aug 29, 2017
@feiskyer
Copy link
Member

/retest

@yujuhong
Copy link
Contributor

yujuhong commented Sep 1, 2017

/lgtm

Let's get this merged.

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feiskyer, sczizzo, yujuhong

Associated issue: 47800

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 1, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@yujuhong
Copy link
Contributor

yujuhong commented Sep 1, 2017

/test pull-kubernetes-unit

@yujuhong
Copy link
Contributor

yujuhong commented Sep 1, 2017

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 50381, 51307, 49645, 50995, 51523)

@k8s-github-robot k8s-github-robot merged commit 0955f36 into kubernetes:master Sep 1, 2017
@CaoShuFeng
Copy link
Contributor

oops, my pull request was much earlier than this.
#47164

Thanks for fix it as well. 👍

@smparkes
Copy link

smparkes commented Sep 5, 2017

Will this get cherry-picked into 1.6 and 1.7? Causing a bunch of problems for us ...

@sczizzo
Copy link
Author

sczizzo commented Sep 5, 2017

@smparkes, yeah check out #51872 for release-1.6 and #51871 for release-1.7

k8s-github-robot pushed a commit that referenced this pull request Sep 5, 2017
Automatic merge from submit-queue

Automated cherry pick of #50381 to release-1.6

**What this PR does / why we need it**:

Use local JSON log buffer in parseDockerJSONLog.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #47800

**Special notes for your reviewer**:

**Release note**:

```release-note
Fixed an issue (#47800) where `kubectl logs -f` failed with `unexpected stream type ""`.
```
@wojtek-t wojtek-t added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Sep 6, 2017
k8s-github-robot pushed a commit that referenced this pull request Sep 6, 2017
Automatic merge from submit-queue

Automated cherry pick of #50381 to release-1.7

Cherry pick of #50381  on release-1.7.

#50381: Bugfix: Use local JSON log buffer in parseDockerJSONLog.
@k8s-cherrypick-bot
Copy link

Commit found in the "release-1.7" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl logs -f failed with 'unexpected stream type "" '