-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
store: fix marshaling with sync.Pool #4593
Conversation
294de2d
to
34f505c
Compare
Do not forget to check the length of a slice returned by sync.Pool. Annotate the whole function with comments to aid understanding of it. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
34f505c
to
6278bd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the quick fix.
pkg/store/storepb/custom.go
Outdated
m.respBuf = poolBuf.(*[]byte) | ||
respBuf = *m.respBuf | ||
} | ||
m.respBuf = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I don't think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, LGTM, just one nit.
pkg/store/storepb/custom.go
Outdated
m.respBuf = poolBuf.(*[]byte) | ||
respBuf = *m.respBuf | ||
} | ||
m.respBuf = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I don't think so
} | ||
|
||
// Fast path with sync.Pool. | ||
// m.respBuf must not be nil so that it would be returned to the pool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to non nil if we do the work below? Can we always do that and remove any outside call pool Get?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understood this comment. The callers using the old function pass nil
thus we need to handle this case - it is not guaranteed that the pool exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, i thought we can simplify, and allow this method to Get
, never pass it from outside - not a biggie
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
4a4b254
to
7f8331f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we still have this data race we discussed here here https://cloud-native.slack.com/archives/CL25937SP/p1629797444067700
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not fix everything, but fix some of things. LGTM and let's iterate.
This reverts commit 8b4c3c9. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
* Revert "store: fix marshaling with sync.Pool (#4593)" This reverts commit 8b4c3c9. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * Revert "[v2] store: reuse buffers for serializing Series() responses (#4535)" This reverts commit 7a8d189. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Do not forget to check the length of a slice returned by sync.Pool.
Annotate the whole function with comments to aid understanding of it.
Cover the case with a test that fails on
main
.Fixes #4591.
cc @yeya24 as you've noticed this too
Signed-off-by: Giedrius Statkevičius giedrius.statkevicius@vinted.com