BewareMyPower commented on code in PR #1494:
URL: https://github.com/apache/pulsar-client-go/pull/1494#discussion_r3231795571


##########
pulsar/consumer_impl.go:
##########
@@ -781,15 +773,22 @@ func (c *consumer) SeekByTime(time time.Time) error {
        return errs
 }
 
-func (c *consumer) checkMsgIDPartition(msgID MessageID) error {
+func (c *consumer) findPartitionConsumer(msgID MessageID) (*partitionConsumer, 
error) {
+       c.Lock()
+       defer c.Unlock()
+       return c.unsafeFindPartitionConsumer(msgID)
+}
+
+// NOTE: This method must be called when c.Lock is held
+func (c *consumer) unsafeFindPartitionConsumer(msgID MessageID) 
(*partitionConsumer, error) {
        partition := msgID.PartitionIdx()
        if partition < 0 || int(partition) >= len(c.consumers) {
                c.log.Errorf("invalid partition index %d expected a partition 
between [0-%d]",
                        partition, len(c.consumers))
-               return fmt.Errorf("invalid partition index %d expected a 
partition between [0-%d]",
+               return nil, fmt.Errorf("invalid partition index %d expected a 
partition between [0-%d]",
                        partition, len(c.consumers))
        }
-       return nil
+       return c.consumers[msgID.PartitionIdx()], nil

Review Comment:
   Why could it be nil? There is already an index range check before. It should 
be safe with `c.Lock` acquired. If it's `nil`, there must be something wrong 
with the modification, which is also protected by `c.Lock`.



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

Reply via email to