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 issue where PostingsForMatchersCache can cache a context cancellation error #546

Merged

Conversation

charleskorn
Copy link
Contributor

If the initial request for a set of matchers to PostingsForMatchersCache.PostingsForMatchers() cancels its context before the call returns, this cancellation can be cached, causing all subsequent calls to the cache for the same matchers to also return a context cancellation error while the cache entry is still live.

While this PR is sufficient to fix the problem above, there are some further improvements we could consider in the future:

  • Should other kinds of errors also not be cached?
  • If all waiting calls to PostingsForMatchersCache.PostingsForMatchers() have cancelled their context, should we cancel the context passed to the underlying PostingsForMatchers implementation?

@aknuds1 aknuds1 added the bug Something isn't working label Oct 20, 2023
Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

LGTM; I had to fix postingsForMatcherPromise.result, so it's deterministic and doesn't randomly fail tests.

@aknuds1 aknuds1 merged commit d0d6240 into main Oct 20, 2023
5 of 6 checks passed
@aknuds1 aknuds1 deleted the charleskorn/postingsformatcherscache-context-cancellation branch October 20, 2023 14:47
aknuds1 added a commit that referenced this pull request Oct 20, 2023
…ache-context-cancellation

Fix issue where `PostingsForMatchersCache` can cache a context cancellation error
promise = oldPromise.(*postingsForMatcherPromise)
return promise.result
// promise was not stored, we return a previously stored promise, that's possibly being fulfilled in another goroutine
close(promise.done)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aknuds1 why is closing the channel here necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

@charleskorn I guess it was old habit, thinking that the unused channel should be closed, but thinking it through again, it's actually not necessary. It should make no difference for garbage collection, AFAIK.

aknuds1 added a commit that referenced this pull request Oct 23, 2023
…ache-context-cancellation

Fix issue where `PostingsForMatchersCache` can cache a context cancellation error
aknuds1 added a commit that referenced this pull request Oct 26, 2023
…ache-context-cancellation

Fix issue where `PostingsForMatchersCache` can cache a context cancellation error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants