streamnative / pulsar-client-go

Apache Pulsar Go Client Library
https://pulsar.apache.org/
Apache License 2.0
1 stars 2 forks source link

ISSUE-707: Race condition detected for producer/consumer when encryption is enabled #256

Open sijie opened 2 years ago

sijie commented 2 years ago

Original Issue: apache/pulsar-client-go#707


Expected behaviour

Creation of producer/consumer on partitioned topic should not run into race condition.

Actual behaviour

For partitioned topic, creation of producer and consumer run into race condition when trying to set DefaultMessageCrypto if it is not provided in the options.

Steps to reproduce

add a test case https://github.com/GPrabhudas/pulsar-client-go/commit/039bbd0e6fec7452ecb90fd28a4165781631d68c

Test case fails with below warnings

....pulsar-client-go/pulsar/testing.go:1093: race detected during execution of test
--- FAIL: TestPartitionTopicsConsumerPubSubEncryption (1.06s)
=== CONT
    ....pulsar-client-go/pulsar/testing.go:1093: race detected during execution of test
FAIL
FAIL    github.com/apache/pulsar-client-go/pulsar       1.699s

WARNING: DATA RACE
Read at 0x00c0004ec130 by goroutine 294:
  github.com/apache/pulsar-client-go/pulsar.newPartitionConsumer()
      ....pulsar-client-go/pulsar/consumer_partition.go:189 +0x1490
  github.com/apache/pulsar-client-go/pulsar.(*consumer).internalTopicSubscribeToPartitions.func1()
      ....pulsar-client-go/pulsar/consumer_impl.go:348 +0x899

Previous write at 0x00c0004ec130 by goroutine 50:
  github.com/apache/pulsar-client-go/pulsar.newPartitionConsumer()
      ....pulsar-client-go/pulsar/consumer_partition.go:194 +0x172d
  github.com/apache/pulsar-client-go/pulsar.(*consumer).internalTopicSubscribeToPartitions.func1()
      ....pulsar-client-go/pulsar/consumer_impl.go:348 +0x899

Goroutine 294 (running) created at:
  github.com/apache/pulsar-client-go/pulsar.(*consumer).internalTopicSubscribeToPartitions()
      ....pulsar-client-go/pulsar/consumer_impl.go:317 +0x6b4
  github.com/apache/pulsar-client-go/pulsar.newInternalConsumer()
      ....pulsar-client-go/pulsar/consumer_impl.go:208 +0x548
  github.com/apache/pulsar-client-go/pulsar.newConsumer()
      ....pulsar-client-go/pulsar/consumer_impl.go:159 +0x764
  github.com/apache/pulsar-client-go/pulsar.(*client).Subscribe()
      ....pulsar-client-go/pulsar/client_impl.go:162 +0xb7
  github.com/apache/pulsar-client-go/pulsar.TestPartitionTopicsConsumerPubSubEncryption()
      ....pulsar-client-go/pulsar/consumer_test.go:416 +0xb16
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1194 +0x202

Goroutine 50 (running) created at:
  github.com/apache/pulsar-client-go/pulsar.(*consumer).internalTopicSubscribeToPartitions()
      ....pulsar-client-go/pulsar/consumer_impl.go:317 +0x6b4
  github.com/apache/pulsar-client-go/pulsar.newInternalConsumer()
      ....pulsar-client-go/pulsar/consumer_impl.go:208 +0x548
  github.com/apache/pulsar-client-go/pulsar.newConsumer()
      ....pulsar-client-go/pulsar/consumer_impl.go:159 +0x764
  github.com/apache/pulsar-client-go/pulsar.(*client).Subscribe()
      ....pulsar-client-go/pulsar/client_impl.go:162 +0xb7
  github.com/apache/pulsar-client-go/pulsar.TestPartitionTopicsConsumerPubSubEncryption()
      ....pulsar-client-go/pulsar/consumer_test.go:416 +0xb16
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1194 +0x202
==================