Jim-Lambert-Bose commented on a change in pull request #121: [Issue 120]
[connection_pool.go] fixing data race when GetConnection() reads connection
attribs
URL: https://github.com/apache/pulsar-client-go/pull/121#discussion_r356827397
##########
File path: pulsar/internal/connection_pool.go
##########
@@ -53,15 +53,21 @@ func (p *connectionPool) GetConnection(logicalAddr
*url.URL, physicalAddr *url.U
cachedCnx, found := p.pool.Load(logicalAddr.Host)
if found {
cnx := cachedCnx.(*connection)
- log.Debug("Found connection in cache:", cnx.logicalAddr,
cnx.physicalAddr)
+ cnx.Lock()
+ // stash these vars, so we can release the lock ASAP
+ // (without using a defer, which holds it until the end of the
func)
+ logicalAddr = cnx.logicalAddr
+ physicalAddr = cnx.physicalAddr
+ cnx.Unlock()
Review comment:
Hum... you're correct. I can't reproduce the race condition I saw earlier
and it could have been related to the other PR I submitted today. I'll close
this. Ty for the review.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services