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 nil panic in proxy heap #5746

Merged
merged 4 commits into from
Oct 2, 2022

Conversation

GiedriusS
Copy link
Member

With lazy proxying we need to wait for at least one response before we can build a heap properly.

Closes #5717 Fixes #5552.

Improved e2e tests to cover this case. cc @matej-g @fpetkovski

Signed-off-by: Giedrius Statkevičius giedrius.statkevicius@vinted.com

With lazy proxying we need to wait for at least one response before we
can build a heap properly.

Closes thanos-io#5717
Fixes thanos-io#5552.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
return true
}

for len(l.bufferedResponses) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to unlock the mutex here before waiting?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, Wait() already takes care of everything for us: https://pkg.go.dev/sync#Cond.Wait.

fpetkovski
fpetkovski previously approved these changes Sep 30, 2022
Copy link
Contributor

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix. Would #5742 (comment) also get resolved by this?

@GiedriusS
Copy link
Member Author

Thanks for the quick fix. Would #5742 (comment) also get resolved by this?

Yep, I have tested these changes with your PR. It was 100% reproducible before and I couldn't reproduce the nil panic after these changes.

matej-g
matej-g previously approved these changes Sep 30, 2022
Copy link
Collaborator

@matej-g matej-g left a comment

Choose a reason for hiding this comment

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

The fix is looking good to me, I was just looking at this 👍

One question related with #5717 (comment) though, do we then still need to handle 0 response case in https://github.com/thanos-io/thanos/blob/main/pkg/store/proxy_heap.go#L114? I'd want to avoid returning nil if that's not a valid case if we are not handling it, to make the code more obvious.

@GiedriusS
Copy link
Member Author

The fix is looking good to me, I was just looking at this +1

One question related with #5717 (comment) though, do we then still need to handle 0 response case in https://github.com/thanos-io/thanos/blob/main/pkg/store/proxy_heap.go#L114? I'd want to avoid returning nil if that's not a valid case if we are not handling it, to make the code more obvious.

Good point. Maybe we could even add a panic() there? What do you think about that? Because it's pretty much a bug to call At() before Next() and At() shouldn't be called if Next() returns false 😄

@matej-g
Copy link
Collaborator

matej-g commented Sep 30, 2022

The fix is looking good to me, I was just looking at this +1
One question related with #5717 (comment) though, do we then still need to handle 0 response case in https://github.com/thanos-io/thanos/blob/main/pkg/store/proxy_heap.go#L114? I'd want to avoid returning nil if that's not a valid case if we are not handling it, to make the code more obvious.

Good point. Maybe we could even add a panic() there? What do you think about that? Because it's pretty much a bug to call At() before Next() and At() shouldn't be called if Next() returns false smile

Yeah, given that it's really an "invalid case", this solution makes sense to me 👍

This is pretty much a bug if this ever happens so complain loudly.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
@matej-g
Copy link
Collaborator

matej-g commented Sep 30, 2022

Just ran this also on top #5552, everything is working as expect 👌, nice job!

Whoop, just look like one test in the proxy needs adjusting (probably just remove the nil assertion since it panics).

@yeya24
Copy link
Contributor

yeya24 commented Sep 30, 2022

This is nice. @GiedriusS We want to tag v0.28.1 for this?

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 1, 2022
@GiedriusS
Copy link
Member Author

This is nice. @GiedriusS We want to tag v0.28.1 for this?

This code is not in 0.28.0 and it's under a hidden flag, by the way (:

@GiedriusS GiedriusS merged commit d533abf into thanos-io:main Oct 2, 2022
@GiedriusS GiedriusS deleted the fix_proxy_heap_nil branch October 2, 2022 17:41
utukJ pushed a commit to utukJ/thanos that referenced this pull request Oct 13, 2022
* store: fix nil panic in proxy heap

With lazy proxying we need to wait for at least one response before we
can build a heap properly.

Closes thanos-io#5717
Fixes thanos-io#5552.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* store: panic if At() called without Next()

This is pretty much a bug if this ever happens so complain loudly.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

* store: adjust test after recent changes

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: utukj <utukphd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants