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

Report parsing error in json serializer #63668

Merged

Conversation

ash2k
Copy link
Member

@ash2k ash2k commented May 10, 2018

What this PR does / why we need it:
Fixes missing error reporting in json parsing using the json-iterator library. Also introduces a private copy of the library config to partially shield from external mutations. json-iterator/go#265.

Special notes for your reviewer:
Found while working on refactoring in #63284.

Release note:

NONE

/kind bug
/sig api-machinery
/cc wojtek-t liggitt

@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label May 10, 2018
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 10, 2018
*(*interface{})(ptr) = f64
return
}
iter.ReportError("DecodeNumber", err.Error())
Copy link
Member Author

Choose a reason for hiding this comment

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

This line is missing in the deleted snippet below. Everything else is exactly the same.

*(*interface{})(ptr) = iter.Read()
}
}
jsoniter.RegisterTypeDecoderFunc("interface {}", decodeNumberAsInt64IfPossible)
Copy link
Member Author

Choose a reason for hiding this comment

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

This mutates some package level field inside of the library. 😞

@lavalamp
Copy link
Member

/assign @roycaihw

@ash2k
Copy link
Member Author

ash2k commented May 17, 2018

@kubernetes/sig-api-machinery-bugs PTAL

Copy link
Member

@roycaihw roycaihw left a comment

Choose a reason for hiding this comment

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

Sorry I didn't get to this earlier. It lgtm in general. I left one comment.

// Private copy of jsoniter.ConfigCompatibleWithStandardLibrary to try to shield against possible mutations
// from outside. Still does not protect from package level jsoniter.Register*() functions - someone calling them
// in some other library will mess with every usage of the jsoniter library in the whole program.
// See https://github.com/json-iterator/go/issues/265
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the pointer. Is there any thing we can do to prevent misusing package level jsoniter.Register*() functions? Did a quick search in our code base and currently this file seems to be the only place using it.

Since I see your effort changing use of encoding/json to github.com/json-iterator/go, does it worth adding some linter/script in CI/makerule that blocks any use of jsoniter.Register*() functions, in case we adopt more and more use of jsoniter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there any thing we can do to prevent misusing package level jsoniter.Register*() functions? Did a quick search in our code base and currently this file seems to be the only place using it.

I think the right thing is to fix the library but the maintainer thinks it is not a problem so... We can have a linting script, as you pointed out. However, I just want to fix the bug and I don't have time to add a linter. Can create a ticket to track this work but I doubt anyone will pick it up :)

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you and I see the maintainer's point. It would be great if you could open a ticket to track the linting work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure #64010

@roycaihw
Copy link
Member

Thanks @ash2k.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 18, 2018
@ash2k
Copy link
Member Author

ash2k commented May 18, 2018

/retest

@ash2k
Copy link
Member Author

ash2k commented May 18, 2018

/assign deads2k
For approval please

@deads2k
Copy link
Contributor

deads2k commented May 21, 2018

/assign deads2k
For approval please

I wasn't involved in jsoniter. I think @thockin worked on that.

/assign @thockin

@ash2k
Copy link
Member Author

ash2k commented May 23, 2018

/retest

2 similar comments
@ash2k
Copy link
Member Author

ash2k commented May 28, 2018

/retest

@ash2k
Copy link
Member Author

ash2k commented May 29, 2018

/retest

// in some other library will mess with every usage of the jsoniter library in the whole program.
// See https://github.com/json-iterator/go/issues/265
configCompatibleWithStandardLibrary = jsoniter.Config{
EscapeHTML: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs a test to detect drift.

Copy link
Member

Choose a reason for hiding this comment

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

This is my biggest concert with this PR. Can we start with their struct and make a deepcopy or something? Can we get them (upstream) to have an immutable baseline object and then a mutable one that derives from that. Then we can skip th emutable one, but stay in sync with the base?

Copy link
Member Author

Choose a reason for hiding this comment

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

@thockin

Can we start with their struct and make a deepcopy or something?

We cannot make a copy because jsoniter.ConfigCompatibleWithStandardLibrary is an interface.

Can we get them (upstream) to have an immutable baseline object and then a mutable one that derives from that. Then we can skip th emutable one, but stay in sync with the base?

I have tried to communicate the issue but failed. See json-iterator/go#265.

I don't want to boil the ocean here, just want to fix the bug. I can reduce the scope of this PR to just add the missing error handling line. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, it is sad, but... what else can I do?

Copy link
Member

Choose a reason for hiding this comment

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

Can we get them to expose the pre-Froze() struct so we can copy that and Froze() it ourself?

Copy link
Member

Choose a reason for hiding this comment

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

Rather than race to get this in 1.11, is it a big deal to try to get good resolution to this issue and then aim for 1.12 ? Is there any real issue being triggered?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this can be delayed until later.

// in some other library will mess with every usage of the jsoniter library in the whole program.
// See https://github.com/json-iterator/go/issues/265
configCompatibleWithStandardLibrary = jsoniter.Config{
EscapeHTML: true,
Copy link
Member

Choose a reason for hiding this comment

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

This is my biggest concert with this PR. Can we start with their struct and make a deepcopy or something? Can we get them (upstream) to have an immutable baseline object and then a mutable one that derives from that. Then we can skip th emutable one, but stay in sync with the base?

// from outside. Still does not protect from package level jsoniter.Register*() functions - someone calling them
// in some other library will mess with every usage of the jsoniter library in the whole program.
// See https://github.com/json-iterator/go/issues/265
configCompatibleWithStandardLibrary = jsoniter.Config{
Copy link
Member

Choose a reason for hiding this comment

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

Do we use jsoniter elsewhere? I.e. do we need our ow pkg/util/json that exposes this?

Copy link
Member Author

Choose a reason for hiding this comment

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

My plan was to use k8s.io/apimachinery/pkg/util/json (which uses jsoniter) everywhere in k/k to get performance benefits across the board. See WIP #63284.

@thockin
Copy link
Member

thockin commented May 31, 2018

I'm going to approve this for now, but I I'm asking you to not drop this topic - I am sure we can get them to do something to make drift less likely. Loop me in if you need, please.

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 31, 2018
@dims
Copy link
Member

dims commented Jun 4, 2018

/milestone v1.11

/hold

@thockin @ash2k please remove hold if you need this for 1.11

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 4, 2018
@k8s-ci-robot k8s-ci-robot added this to the v1.11 milestone Jun 4, 2018
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete

@ash2k @deads2k @roycaihw @thockin

Action required: This pull request requires label changes. If the required changes are not made within 3 days, the pull request will be moved out of the v1.11 milestone.

priority: Must specify exactly one of priority/critical-urgent, priority/important-longterm or priority/important-soon.

Help

@jberkus
Copy link

jberkus commented Jun 4, 2018

@thockin @ash2k if you need this in 1.11, please add priority and approved-for-milestone labels. Thanks!

@thockin
Copy link
Member

thockin commented Jun 4, 2018

Rather than race to get this in 1.11, is it a big deal to try to get good resolution to this issue and then aim for 1.12 ? Is there any real issue being triggered?

@dims
Copy link
Member

dims commented Jun 4, 2018

sounds like a plan @thockin

/milestone clear

@k8s-ci-robot k8s-ci-robot removed this from the v1.11 milestone Jun 4, 2018
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 16, 2018
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jun 18, 2018
@ash2k
Copy link
Member Author

ash2k commented Jun 20, 2018

@roycaihw lost LGTM due to rebase. Thanks

@roycaihw
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 Jun 20, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ash2k, roycaihw, thockin

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

@ash2k
Copy link
Member Author

ash2k commented Jun 21, 2018

@dims can you cancel the hold please

@dims
Copy link
Member

dims commented Jun 21, 2018

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 21, 2018
@k8s-github-robot
Copy link

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

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 1a75395 into kubernetes:master Jun 21, 2018
@ash2k ash2k deleted the jsoniter-error-handling branch June 21, 2018 05:11
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. 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. milestone/incomplete-labels 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

10 participants