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(pubsub): mitigate race in checking ordering config #4602
Merged
gcf-merge-on-green
merged 2 commits into
googleapis:master
from
hongalex:pubsub-fix-ordering-race
Aug 12, 2021
Merged
fix(pubsub): mitigate race in checking ordering config #4602
gcf-merge-on-green
merged 2 commits into
googleapis:master
from
hongalex:pubsub-fix-ordering-race
Aug 12, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google-cla
bot
added
the
cla: yes
This human has signed the Contributor License Agreement.
label
Aug 12, 2021
codyoss
approved these changes
Aug 12, 2021
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
hongalex
changed the title
test(pubsub): fix race in checking ordering config
test(pubsub): mitigate race in checking ordering config
Aug 12, 2021
hongalex
changed the title
test(pubsub): mitigate race in checking ordering config
fix(pubsub): mitigate race in checking ordering config
Aug 12, 2021
hongalex
added
automerge
Merge the pull request once unit tests and other checks pass.
kokoro:force-run
Add this label to force Kokoro to re-run the tests.
labels
Aug 12, 2021
kokoro-team
removed
the
kokoro:force-run
Add this label to force Kokoro to re-run the tests.
label
Aug 12, 2021
gcf-merge-on-green
bot
removed
the
automerge
Merge the pull request once unit tests and other checks pass.
label
Aug 12, 2021
gcf-merge-on-green bot
pushed a commit
that referenced
this pull request
Aug 13, 2021
In the previous iteration of this PR, #4602, the assumption was made that making the config check earlier will prevent race conditions in the test, which turned out to be incorrect. In addition, although previously ruled out as a solution, this PR makes it so that a config check is always made on the first call to `Receive`. I originally thought this would result in a poor experience for those users who don't have the `roles/pubsub.viewer` permission, but we default `enableOrdering` to `true` anyway if the config call fails due to lack of permissions. Using a default of `true` only negatively impacts those who don't want ordering on their subscription, and this behavior is [already documented](https://github.com/googleapis/google-cloud-go/blob/pubsub/v1.14.0/pubsub/subscription.go#L235-L239). Fixes #3626
gcf-merge-on-green bot
pushed a commit
that referenced
this pull request
Aug 13, 2021
🤖 I have created a release \*beep\* \*boop\* --- ## [1.15.0](https://www.github.com/googleapis/google-cloud-go/compare/pubsub/v1.14.0...pubsub/v1.15.0) (2021-08-13) ### Features * **pubsub:** Add topic retention options ([5996846](https://www.github.com/googleapis/google-cloud-go/commit/59968462a3870c6289166fa1161f9b6d9c10e093)) ### Bug Fixes * **pubsub:** always make config check to prevent race ([#4606](https://www.github.com/googleapis/google-cloud-go/issues/4606)) ([8cfcf53](https://www.github.com/googleapis/google-cloud-go/commit/8cfcf53d03b9b442e7f0bc1c1b20c791e31c07b0)), refs [#3626](https://www.github.com/googleapis/google-cloud-go/issues/3626) * **pubsub:** mitigate race in checking ordering config ([#4602](https://www.github.com/googleapis/google-cloud-go/issues/4602)) ([112eea2](https://www.github.com/googleapis/google-cloud-go/commit/112eea20b46bbc34e5f8f65b9812fb3e60107409)), refs [#3626](https://www.github.com/googleapis/google-cloud-go/issues/3626) * **pubsub:** replace IAMPolicy in API config ([5996846](https://www.github.com/googleapis/google-cloud-go/commit/59968462a3870c6289166fa1161f9b6d9c10e093)) 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
Labels
api: pubsub
Issues related to the Pub/Sub API.
cla: yes
This human has signed the Contributor License Agreement.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use
sync.once.Do(s.checkOrdering)
to perform one config check for a subscription's message ordering field when a message with an ordering key is received. This way, we know if we should deliver messages in order. However, sincesub.Receive
generates multiple goroutines,s.enableOrdering
is not guaranteed to be read after the first invocation ofs.checkOrdering
. This PR makes this race happen less often by making the config check closer to when the message is received.This cannot be fully eliminated without making the config call at the start of every single
Receive
. This behavior is less desirable, as we want to make the config call only when we have to, that is when we receive a message with an ordering key.Fixes #3626