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): prevent infinite retry with publishing invalid utf-8 chars #5728

Merged
merged 6 commits into from
Mar 7, 2022

Conversation

hongalex
Copy link
Member

@hongalex hongalex commented Mar 4, 2022

INTERNAL is a retryable code for Publish but we should not indefinitely retry this error code when message attributes contains invalid utf-8 characters, which the grpc-go library returns as an INTERNAL error.

I made the decision to have the custom publish retry settings (currently just the invalid wrapping) take precedence over both the retry settings defined in the GAPIC layer, as well as user-specified custom retry. This is because we have no good way to detect whether or not the underlying GAPIC publisher client is using the default retry settings or a user specified version. Currently, there is no reason for users to need to override the custom publisher retry (since invalid utf-8 characters should never be retried), but this may change in the future. An alternative is to hard code the value of the default GAPIC publish retry settings to compare against, but this solution is inelegant.

Fixes #5268

@hongalex hongalex requested review from a team as code owners March 4, 2022 23:45
@product-auto-label product-auto-label bot added the size: xs Pull request size is extra small. label Mar 4, 2022
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Mar 4, 2022
@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Mar 5, 2022
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.

Just one minor nit, or else LGTM

pubsub/service.go Outdated Show resolved Hide resolved
@hongalex hongalex merged commit 0a4dab9 into googleapis:main Mar 7, 2022
BrennaEpp pushed a commit to BrennaEpp/google-cloud-go that referenced this pull request Mar 10, 2022
…rs (googleapis#5728)

* fix(pubsub): prevent infinite retry with publishing invalid utf-8 chars

* use user specified publish retryer if provided

* wrap default/user retry settings with custom publish retryer

* remove switch statement since theres only one case
@hongalex hongalex deleted the pubsub-retry-invalid-utf8 branch February 27, 2023 22:01
@hongalex hongalex mentioned this pull request Feb 27, 2023
@AndreasBergmeier6176
Copy link

Why not rather validate whether attribute values are valid UTF-8 to begin with? Wouldn't that be more elegant?

@hongalex
Copy link
Member Author

It's cheaper to punt the behavior down to the gRPC level and have it bubble up the marshaling error, rather than add another check for every publish call to detect if there are UTF-8 characters.

Did this cause an issue for you recently?

@AndreasBergmeier6176
Copy link

It's cheaper to punt the behavior down to the gRPC level and have it bubble up the marshaling error, rather than add another check for every publish call to detect if there are UTF-8 characters.

Did this cause an issue for you recently?

Well, it might be cheaper but figuring out which of the attributes is the actual problem is a PITA. Especially if you have multiple layers of software that modifies the attributes. If the gRPC level would at least report, what the failing attribute key was...

@hongalex
Copy link
Member Author

If the gRPC level would at least report, what the failing attribute key was...

If you get back the string field contains invalid UTF-8 error, consider iterating over the attributes and call utf8.ValidString to see which attribute failed.

@AndreasBergmeier6176
Copy link

If the gRPC level would at least report, what the failing attribute key was...

If you get back the string field contains invalid UTF-8 error, consider iterating over the attributes and call utf8.ValidString to see which attribute failed.

I think I would do that if the gRPC module would export said error. Currently nothing is preventing the gRPC implementation from just doing a rug-pull and use yet another error string.

@hongalex
Copy link
Member Author

Yeah 100% agree that catching this based on the error string is brittle (and is what we're currently doing as well in the library). Are you willing to open an issue against grpc-go for this issue (needing to export the error)?

@AndreasBergmeier6176
Copy link

Yeah 100% agree that catching this based on the error string is brittle (and is what we're currently doing as well in the library). Are you willing to open an issue against grpc-go for this issue (needing to export the error)?

See here: golang/protobuf#1642

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: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubsub: infinite retry because of invalid utf-8 characters in attributes
3 participants