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


##########
pulsar/producer_impl.go:
##########
@@ -277,8 +280,8 @@ func (p *producer) internalCreatePartitionsProducers() 
error {
        } else {
                p.metrics.ProducersPartitions.Add(float64(partitionsToAdd))
        }
-       atomic.StorePointer(&p.producersPtr, unsafe.Pointer(&p.producers))
-       atomic.StoreUint32(&p.numPartitions, uint32(len(p.producers)))
+       atomic.StorePointer(&p.producersPtr, unsafe.Pointer(&producers))

Review Comment:
   This modification make it worse than the existing code. Now `producers` is 
just a local field, so ~~it could be garbaged collected even if it's tracked by 
an **UNSAFE POINTER**.~~ (determined by the implementation details)
   
   > Dangling Pointers: If you create an unsafe pointer to this local slice and 
then return that pointer (or otherwise allow it to "escape" the function's 
scope), you'll end up with a dangling pointer. This pointer points to memory 
that is no longer valid for your use.



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