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

store: fix marshaling with sync.Pool #4593

Merged
merged 3 commits into from
Aug 24, 2021
Merged

Conversation

GiedriusS
Copy link
Member

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

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>
yeya24
yeya24 previously approved these changes Aug 24, 2021
Copy link
Contributor

@yeya24 yeya24 left a 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.

m.respBuf = poolBuf.(*[]byte)
respBuf = *m.respBuf
}
m.respBuf = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this line necessary?

Copy link
Member

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

bwplotka
bwplotka previously approved these changes Aug 24, 2021
Copy link
Member

@bwplotka bwplotka left a 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.

m.respBuf = poolBuf.(*[]byte)
respBuf = *m.respBuf
}
m.respBuf = nil
Copy link
Member

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.
Copy link
Member

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?

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'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

Copy link
Member

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

pkg/store/storepb/custom.go Show resolved Hide resolved
pkg/store/storepb/custom_test.go Outdated Show resolved Hide resolved
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
@GiedriusS GiedriusS dismissed stale reviews from bwplotka and yeya24 via 11d3694 August 24, 2021 10:22
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Copy link
Member

@bwplotka bwplotka left a 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

Copy link
Member

@bwplotka bwplotka left a 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.

@bwplotka bwplotka merged commit 8b4c3c9 into thanos-io:main Aug 24, 2021
GiedriusS added a commit to GiedriusS/thanos that referenced this pull request Aug 27, 2021
This reverts commit 8b4c3c9.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
bwplotka pushed a commit that referenced this pull request Aug 27, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store The request returns inconsistent data and reports an error
3 participants