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): move flow control release to callback completion #9311

Merged
merged 3 commits into from Jan 26, 2024

Conversation

hongalex
Copy link
Member

This moves the flow control release to the end of the user callback rather than to the message doneFunc. This further emphasizes the importance of calling ack and nack within the callback, since calling ack in a goroutine could mean that flow control resources are released too early. This behavior is already documented

Fixes #9309
Internal issue: 322090131

@hongalex hongalex requested review from shollyman and a team as code owners January 26, 2024 01:25
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: pubsub Issues related to the Pub/Sub API. labels Jan 26, 2024
wg.Add(1)
// Make sure the subscription has ordering enabled before adding to scheduler.
var key string
if s.enableOrdering {
key = msg.OrderingKey
}
// TODO(deklerk): Can we have a generic handler at the
// constructor level?
msgLen := len(msg.Data)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not super familiar with msg lifecycle here. Is it possible for the user to alter msg.Data between acquire and release, which could cause the flow controller to get out of sync? If so, it might make sense to compute the length once and pass that to acquire and release.

Copy link
Member Author

Choose a reason for hiding this comment

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

At this point, the message hasn't been dispatched to the user yet. This is all pre-processing, where the message isn't changed.

@hongalex hongalex enabled auto-merge (squash) January 26, 2024 17:52
@hongalex hongalex merged commit 2b6b0da into googleapis:main Jan 26, 2024
9 checks passed
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. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubsub: expired messages clog up flow control
2 participants