From 137d24e50ac5ddc6af7e28f9434d92d377e21a36 Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:40:19 -0700 Subject: [PATCH] test(pubsub): fix race in checking ordering config --- pubsub/subscription.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubsub/subscription.go b/pubsub/subscription.go index 5eca508ee23..d228ed12c33 100644 --- a/pubsub/subscription.go +++ b/pubsub/subscription.go @@ -897,6 +897,9 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes } for i, msg := range msgs { msg := msg + if msg.OrderingKey != "" { + s.once.Do(s.checkOrdering) + } // TODO(jba): call acquire closer to when the message is allocated. if err := fc.acquire(ctx, len(msg.Data)); err != nil { // TODO(jba): test that these "orphaned" messages are nacked immediately when ctx is done. @@ -914,9 +917,6 @@ func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Mes old(ackID, ack, receiveTime) } wg.Add(1) - if msg.OrderingKey != "" { - s.once.Do(s.checkOrdering) - } // Make sure the subscription has ordering enabled before adding to scheduler. var key string if s.enableOrdering {