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): make config call permission error in Receive transparent #3985

Merged
merged 8 commits into from Apr 23, 2021
27 changes: 23 additions & 4 deletions pubsub/subscription.go
Expand Up @@ -224,7 +224,18 @@ type SubscriptionConfig struct {
// The set of labels for the subscription.
Labels map[string]string

// EnableMessageOrdering enables message ordering.
// EnableMessageOrdering enables message ordering on this subscription.
// This value is only used for subscription creation and update, and
// is not used directly client-side, such as in calls to Subscription.Receive.
//
// If set to false, even if messages are published with ordering keys,
// messages will not be delivered in order.
//
// When calling Subscription.Receive, the client will try to populate this
// value from the subscription config with a call to Subscription.Config(),
// which requires the roles/viewer or roles/pubsub.viewer role on your
// service account. If that call fails due to insufficient permissions,
// mesages will be delivered in order.
EnableMessageOrdering bool

// DeadLetterPolicy specifies the conditions for dead lettering messages in
Expand Down Expand Up @@ -774,13 +785,21 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes
s.mu.Unlock()
defer func() { s.mu.Lock(); s.receiveActive = false; s.mu.Unlock() }()

// Check config to check EnableMessageOrdering field.
// Check config to check EnableMessageOrdering field. If this
// call fails with a permissions error, because the service account
// doesn't have the roles/viewer or roles/pubsub.viewer role, we
// will assume EnableMessageOrdering to be true.
// See: https://github.com/googleapis/google-cloud-go/issues/3884
cfg, err := s.Config(ctx)
if err != nil {
return fmt.Errorf("sub.Config err: %v", err)
if status.Code(err) == codes.PermissionDenied {
s.enableOrdering = true
} else {
return fmt.Errorf("sub.Config err: %v", err)
}
} else {
s.enableOrdering = cfg.EnableMessageOrdering
}
s.enableOrdering = cfg.EnableMessageOrdering

maxCount := s.ReceiveSettings.MaxOutstandingMessages
if maxCount == 0 {
Expand Down