dferstay commented on a change in pull request #535:
URL: https://github.com/apache/pulsar-client-go/pull/535#discussion_r647628798



##########
File path: pulsar/consumer_partition.go
##########
@@ -971,9 +972,9 @@ func (pc *partitionConsumer) grabConn() error {
                pc.name = res.Response.ConsumerStatsResponse.GetConsumerName()
        }
 
-       pc.conn = res.Cnx
+       pc._setConn(res.Cnx)
        pc.log.Info("Connected consumer")
-       pc.conn.AddConsumeHandler(pc.consumerID, pc)
+       pc._getConn().AddConsumeHandler(pc.consumerID, pc)

Review comment:
       @cckellogg ,
   
   Good question; `_getConn()` should never return `nil`.
   
   An invariant in this code is that the `partitionConsumer.conn` field must be 
set and is never `nil`.
   The `grabConn()` method sets the `partitionConsumer.conn` field; 
`grabConn()` is called from the `newPartitionConsumer` factory method which 
will fail construction of the partitionConsumer if grabConn() returns an error.
   
   The above said, it is probably better for the cast in `_getConn()` to be 
unchecked and let the code `panic()` if the invariant is broken.  Thoughts?




-- 
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]


Reply via email to