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

fix: Workaround Go Inet marshal bug #410

Merged
merged 5 commits into from
Nov 15, 2022
Merged

fix: Workaround Go Inet marshal bug #410

merged 5 commits into from
Nov 15, 2022

Conversation

yevgenypats
Copy link
Member

Fix nasty bug triggered by Go bug

golang/go#35727

@shimonp21 can you please confirm this solves the bug triggered by the k8s cidr plugin.

@github-actions github-actions bot added fix and removed fix labels Nov 15, 2022
@yevgenypats yevgenypats changed the title fix: workaround Go Inet marshal bug fix: Workaround Go Inet marshal bug Nov 15, 2022
@github-actions github-actions bot added fix and removed fix labels Nov 15, 2022
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

I'm assuming this works, but I'll let @shimonp21 verify

Copy link
Member

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Just thinking we should maybe add a test that covers the marshal/unmarshal behavior for all the types to make sure this fix works as expected, doesn't regress and that there aren't other similar bugs lurking in other types.

schema/inet.go Outdated Show resolved Hide resolved
schema/inet.go Outdated
@@ -146,6 +153,22 @@ func maybeGetIPv4(input string, ip net.IP) net.IP {
return ip.To4()
}

// workaround this Golang bug: https://github.com/golang/go/issues/35727
func (dst *Inet) UnmarshalJSON(b []byte) error {
tmp := inetIntermidate{}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tmp := inetIntermidate{}
tmp := inetIntermediate{}

Copy link
Contributor

@shimonp21 shimonp21 left a comment

Choose a reason for hiding this comment

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

This doesn't work. Let's sync on this online?

@yevgenypats yevgenypats requested review from disq, shimonp21, hermanschaaf and erezrokah and removed request for erezrokah November 15, 2022 14:11
@yevgenypats
Copy link
Member Author

@shimonp21 this now works. @hermanschaaf added tests.

}

// workaround this Golang bug: https://github.com/golang/go/issues/35727
if len(r.IPNet.Mask) != len(r2.IPNet.Mask) {
Copy link
Member

Choose a reason for hiding this comment

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

Why compare lengths here, and not the values?

Copy link
Member Author

Choose a reason for hiding this comment

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

because we compare the values in the line before that. the bug was that the bytes are in different length. I can also add a byte comparision.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. No all good, just curious

Copy link
Member Author

Choose a reason for hiding this comment

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

but good call. Added more thorugh tests and also checked that it failed before the fix and after

schema/inet.go Outdated
return err
}
*dst = Inet{Status: tmp.Status}
dst.Status = tmp.Status
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 need this line?

@@ -12,6 +13,12 @@ type InetTransformer interface {
TransformInet(*Inet) interface{}
}

// workaround this Golang bug: https://github.com/golang/go/issues/35727
type inetWrapper struct {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this is only used in Unmarshal.
Maybe order structs so that exported struct Inet is at the top.

Copy link
Contributor

@shimonp21 shimonp21 left a comment

Choose a reason for hiding this comment

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

Approving at @yevgenypats request.
We may still have a bug in handling ipv6 though - testing that right now

@kodiakhq kodiakhq bot merged commit bd7718c into main Nov 15, 2022
@kodiakhq kodiakhq bot deleted the fix/inet_marshal branch November 15, 2022 15:34
kodiakhq bot pushed a commit that referenced this pull request Nov 15, 2022
🤖 I have created a release *beep* *boop*
---


## [1.5.3](v1.5.2...v1.5.3) (2022-11-15)


### Bug Fixes

* Workaround Go Inet marshal bug ([#410](#410)) ([bd7718c](bd7718c))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.

None yet

5 participants