wolfstudy opened a new issue #565:
URL: https://github.com/apache/pulsar-client-go/issues/565


   #### Expected behavior
   
   In `blocking_queue.go`, 
   
   func (bq *blockingQueue) Put(item interface{}) {
        bq.mutex.Lock() // 1. add the lock
        defer bq.mutex.Unlock()
   
        for bq.size == bq.maxSize {
                bq.isNotFull.Wait()
        }
           ...
   }
   
   when `bq.size == bq.maxSize`, It means that the pending queue is full at 
this time, and we use `bq.isNotFull.Wait()` to block the send gorutine here. At 
this point, we look forward to using `peek()` or other methods to consume the 
data from the pending queue, but here is a lock added. In fact, after blocking, 
we have not unlocked yet, so deadlock will occur here.
   
   The peek() logic:
   
   ```
   func (bq *blockingQueue) Peek() interface{} {
        bq.mutex.Lock() // 2. Try again to add the lock
        defer bq.mutex.Unlock()
   
        if bq.size == 0 {
                return nil
        }
        return bq.items[bq.headIdx]
   }
   ```
   
   Therefore, when the following logic is triggered, send gorutine will be 
blocked due to deadlock
   
   ```
        for bq.size == bq.maxSize {
                bq.isNotFull.Wait()
        }
   ```
   
   
   #### Actual behavior
   
   Tell us what happens instead
   
   #### Steps to reproduce
   
   How can we reproduce the issue
   
   #### System configuration
   **Pulsar version**: x.y
   


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