Skip to content

Commit

Permalink
cdc: avoid deadlock on error in pubsub sink
Browse files Browse the repository at this point in the history
cockroachdb#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.
  • Loading branch information
HonoreDB committed Sep 20, 2022
1 parent f7f7466 commit c46a9d0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/ccl/changefeedccl/sink_pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c46a9d0

Please sign in to comment.