equanz opened a new pull request #581:
URL: https://github.com/apache/pulsar-client-go/pull/581
### Motivation
When running test command, the data race warning occurred in my CI
environment.
```
==================
WARNING: DATA RACE
Read at 0x00c0007936c0 by goroutine 472:
github.com/apache/pulsar-client-go/pulsar/internal.(*pulsarServiceNameResolver).ResolveHost()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/service_name_resolver.go:66
+0x167
github.com/apache/pulsar-client-go/pulsar/internal.(*rpcClient).RequestToAnyBroker()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/rpc_client.go:82
+0x70
github.com/apache/pulsar-client-go/pulsar/internal.(*lookupService).GetPartitionedTopicMetadata()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/lookup_service.go:183
+0x2ab
github.com/apache/pulsar-client-go/pulsar.(*client).TopicPartitions()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/client_impl.go:184
+0xfd
github.com/apache/pulsar-client-go/pulsar.(*producer).internalCreatePartitionsProducers()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/producer_impl.go:161
+0xcf
github.com/apache/pulsar-client-go/pulsar.(*producer).runBackgroundPartitionDiscovery.func1()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/producer_impl.go:148
+0x104
Previous write at 0x00c0007936c0 by goroutine 475:
sync/atomic.StoreInt32()
/opt/go/src/runtime/race_amd64.s:242 +0xb
github.com/apache/pulsar-client-go/pulsar/internal.(*pulsarServiceNameResolver).ResolveHost()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/service_name_resolver.go:67
+0x1b1
github.com/apache/pulsar-client-go/pulsar/internal.(*rpcClient).RequestToAnyBroker()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/rpc_client.go:82
+0x70
github.com/apache/pulsar-client-go/pulsar/internal.(*lookupService).Lookup()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/internal/lookup_service.go:109
+0x408
github.com/apache/pulsar-client-go/pulsar.(*partitionConsumer).grabConn()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/consumer_partition.go:897
+0x102
github.com/apache/pulsar-client-go/pulsar.newPartitionConsumer()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/consumer_partition.go:179
+0xc7e
github.com/apache/pulsar-client-go/pulsar.newReader()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/reader_impl.go:105
+0x96c
github.com/apache/pulsar-client-go/pulsar.(*client).CreateReader()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/client_impl.go:170
+0xd7
github.com/apache/pulsar-client-go/pulsar.TestReaderWithMultiHosts()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/reader_test.go:620
+0x6d4
testing.tRunner()
/opt/go/src/testing/testing.go:1193 +0x202
Goroutine 472 (running) created at:
github.com/apache/pulsar-client-go/pulsar.(*producer).runBackgroundPartitionDiscovery()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/producer_impl.go:140
+0x125
github.com/apache/pulsar-client-go/pulsar.newProducer()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/producer_impl.go:128
+0x6ce
github.com/apache/pulsar-client-go/pulsar.(*client).CreateProducer()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/client_impl.go:153
+0xc4
github.com/apache/pulsar-client-go/pulsar.TestReaderWithMultiHosts()
/sd/workspace/src/github.com/apache/pulsar-client-go/pulsar/reader_test.go:603
+0x295
testing.tRunner()
/opt/go/src/testing/testing.go:1193 +0x202
Goroutine 475 (running) created at:
testing.(*T).Run()
/opt/go/src/testing/testing.go:1238 +0x5d7
testing.runTests.func1()
/opt/go/src/testing/testing.go:1511 +0xa6
testing.tRunner()
/opt/go/src/testing/testing.go:1193 +0x202
testing.runTests()
/opt/go/src/testing/testing.go:1509 +0x612
testing.(*M).Run()
/opt/go/src/testing/testing.go:1417 +0x3b3
main.main()
_testmain.go:419 +0x356
==================
time="2021-07-14T11:08:33+09:00" level=info msg="[Connecting to broker]"
remote_addr="pulsar://localhost:6600"
time="2021-07-14T11:08:33+09:00" level=info msg="[Connected consumer]"
consumerID=1 name= subscription=reader-psjga topic=my-topic-508454231
time="2021-07-14T11:08:33+09:00" level=info msg="[Created consumer]"
consumerID=1 name= subscription=reader-psjga topic=my-topic-508454231
time="2021-07-14T11:08:33+09:00" level=info msg="Closing consumer=1"
consumerID=1 name= subscription=reader-psjga topic=my-topic-508454231
time="2021-07-14T11:08:33+09:00" level=info msg="[Closed consumer]"
consumerID=1 name= subscription=reader-psjga topic=my-topic-508454231
time="2021-07-14T11:08:36+09:00" level=warning msg="[Failed to connect to
broker.]" error="dial tcp 127.0.0.1:6600: connect: connection refused"
remote_addr="pulsar://localhost:6600"
time="2021-07-14T11:08:36+09:00" level=info msg="[Connection closed]"
remote_addr="pulsar://localhost:6600"
time="2021-07-14T11:08:36+09:00" level=info msg="[Closing producer]"
producerID=1 producer_name=standalone-0-183
topic="persistent://public/default/my-topic-508454231"
time="2021-07-14T11:08:36+09:00" level=info msg="[Closed producer]"
producerID=1 producer_name=standalone-0-183
topic="persistent://public/default/my-topic-508454231"
time="2021-07-14T11:08:36+09:00" level=info msg="[Connection closed]"
local_addr="127.0.0.1:40190" remote_addr="pulsar://localhost:6650"
--- FAIL: TestReaderWithMultiHosts (3.75s)
testing.go:1092: race detected during execution of test
```
I think this issue is not critical, but I'd like to fix this issue.
### Modifications
* Add mutex in ServiceNameResolver to avoid race condition of
`r.CurrentIndex`
### Verifying this change
- [x] Make sure that the change passes the CI checks.
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (no)
- The public API: (no)
- The schema: (no)
- The default values of configurations: (no)
- The wire protocol: (no)
### Documentation
- Does this pull request introduce a new feature? (no)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]