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

fixes a data race in SerializeObject function #94589

Merged
merged 1 commit into from Sep 9, 2020

Conversation

p0lyn0mial
Copy link
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it: It changes deferredResponseWriter to return after calling the Close() method.
Previously all sorts of errors including a data race were possible because deferredResponseWriter resets the writer and returns it to the pool. An attempt to write to a nil writer will lead to invalid memory address or nil pointer dereference. Sharing the same instance of deferredResponseWriter might lead to index out of range [43] with length 30 and recovered from err index > windowEnd errors

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 7, 2020
@p0lyn0mial
Copy link
Contributor Author

/assign @sttts @mfojtik

@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 7, 2020
}
return
Copy link
Contributor

Choose a reason for hiding this comment

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

change looks good otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

The whole point of &deferredResponseWriter was to be able to write useful errors to the response if there was an encoding error. We should be able to determine if the error came from writing to the underlying http writer, and if not, we should continue trying to write an error to the http response

/hold

Copy link
Member

Choose a reason for hiding this comment

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

edit: never mind, misread the error flow… was thrown off by the non-standard if err == nil early return pattern

/hold cancel

previously all sorts of errors including a data race were possible because deferredResponseWriter resets the writer and returns it to the pool.

an attempt to write to a nil writer will lead to "invalid memory address or nil pointer dereference"
sharing the same instance of deferredResponseWriter might lead to "index out of range [43] with length 30" and "recovered from err index > windowEnd" errors
@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Sep 7, 2020
@sttts sttts added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Sep 8, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Sep 8, 2020
@sttts
Copy link
Contributor

sttts commented Sep 8, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 8, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p0lyn0mial, sttts

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2020
@sttts sttts added this to the v1.20 milestone Sep 9, 2020
@k8s-ci-robot k8s-ci-robot merged commit 425edbb into kubernetes:master Sep 9, 2020
@yogeek
Copy link

yogeek commented Mar 30, 2021

Hi @p0lyn0mial and @sttts ! Can this fix be backported to 1.19 or is the upgrade to 1.20 mandatory please ?

@p0lyn0mial
Copy link
Contributor Author

Hi @p0lyn0mial and @sttts ! Can this fix be backported to 1.19 or is the upgrade to 1.20 mandatory please ?

it was already backported to 1.19 - #98393
this PR was targeting 1.20

@liggitt
Copy link
Member

liggitt commented Mar 30, 2021

this was already backported to 1.18 and 1.19

@yogeek
Copy link

yogeek commented Mar 30, 2021

@p0lyn0mial @liggitt Oh ok, thank you for the quick reply.
So in my current 1.19.8 cluster, normally, the fix is already there ?

I ask this because I arrived here from this one : kubernetes-sigs/prometheus-adapter#292 and we are in 1.19.8 and still observe these errors in the api-server logs :

E0330 13:25:31.344690       1 writers.go:105] apiserver was unable to write a JSON response: http: Handler timeout

Additionnal note : we looked at apiserver logs to try to understand a recent increase in apiserver memory consumption that cause some of our masters to be "NotReady" lately.

@liggitt
Copy link
Member

liggitt commented Mar 30, 2021

still observe these errors in the api-server logs :

E0330 13:25:31.344690       1 writers.go:105] apiserver was unable to write a JSON response: http: Handler timeout

Additionnal note : we looked at apiserver logs to try to understand a recent increase in apiserver memory consumption that cause some of our masters to be "NotReady" lately.

Those are unrelated to this issue. The symptoms of this issue are listed in the description:

An attempt to write to a nil writer will lead to invalid memory address or nil pointer dereference. Sharing the same instance of deferredResponseWriter might lead to index out of range [43] with length 30 and recovered from err index > windowEnd errors

@yogeek
Copy link

yogeek commented Mar 30, 2021

ok @liggitt thank you for your help

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. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants