From c46a9d0e7185ed342d919886b864de5346ef6220 Mon Sep 17 00:00:00 2001 From: Aaron Zinger Date: Tue, 20 Sep 2022 15:56:37 -0400 Subject: [PATCH] cdc: avoid deadlock on error in pubsub sink https://github.com/cockroachdb/cockroach/pull/88130 introduced a deadlock when an attempt to create a topic fails -- the goroutine tries to acquire a lock in order to record the error, but it already has it in order to write to the map. This PR releases the lock while creating the topic, which should also help with performance a bit on startup. Release note (bug fix): Fixed a bug preventing pubsub changefeeds from retrying. --- pkg/ccl/changefeedccl/sink_pubsub.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/ccl/changefeedccl/sink_pubsub.go b/pkg/ccl/changefeedccl/sink_pubsub.go index 02eb168ad62e..cf7b4afda0ea 100644 --- a/pkg/ccl/changefeedccl/sink_pubsub.go +++ b/pkg/ccl/changefeedccl/sink_pubsub.go @@ -355,9 +355,12 @@ func (p *gcpPubsubClient) getTopicClient(name string) (*pubsub.Topic, error) { p.mu.Lock() defer p.mu.Unlock() if topic, ok := p.topics[name]; ok { + p.mu.Unlock() return topic, nil } + p.mu.Unlock() // openTopic may need the lock to record an error topic, err := p.openTopic(name) + p.mu.Lock() if err != nil { return nil, err }