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(pubsub): mitigate race in checking ordering config #4602

Merged

Conversation

hongalex
Copy link
Member

@hongalex hongalex commented Aug 12, 2021

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, since sub.Receive generates multiple goroutines, s.enableOrdering is not guaranteed to be read after the first invocation of s.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

@hongalex hongalex requested review from a team as code owners August 12, 2021 03:50
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Aug 12, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 12, 2021
Copy link
Member

@codyoss codyoss left a comment

Choose a reason for hiding this comment

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

LGTM

@hongalex hongalex changed the title test(pubsub): fix race in checking ordering config test(pubsub): mitigate race in checking ordering config Aug 12, 2021
@hongalex hongalex changed the title test(pubsub): mitigate race in checking ordering config fix(pubsub): mitigate race in checking ordering config Aug 12, 2021
@hongalex 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 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 gcf-merge-on-green bot merged commit 112eea2 into googleapis:master Aug 12, 2021
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Aug 12, 2021
@hongalex hongalex deleted the pubsub-fix-ordering-race branch August 13, 2021 04:20
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
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubsub: TestIntegration_OrderedKeys_JSON failed
3 participants