PavelZeger commented on code in PR #1507:
URL: https://github.com/apache/pulsar-client-go/pull/1507#discussion_r3403432074


##########
pulsar/consumer_partition.go:
##########
@@ -331,6 +338,24 @@ func (p *availablePermits) flowIfNeed() {
        }
 }
 
+func (p *availablePermits) flush() {
+       if p.pc.paused.Load() {
+               return
+       }
+
+       current := p.get()
+       if current > 0 {
+               if !p.permits.CompareAndSwap(current, 0) {
+                       return
+               }
+
+               p.pc.log.Debugf("flushing withheld permits=%d", current)
+               if err := p.pc.internalFlow(uint32(current)); err != nil {
+                       p.pc.log.WithError(err).Error("unable to send permits")
+               }
+       }
+}

Review Comment:
   Fixed. `flush()` now loops on the CAS instead of bailing after one failed 
attempt. If a concurrent `add()` changes the permit count between the read and 
the swap, it just re-reads and tries again. It stops when it either sees 0 
(meaning another path already sent the permits) or successfully swaps to 0 and 
sends exactly that amount - so it can't get stuck and can't over-grant.
     
   



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