wuYin opened a new pull request #457:
URL: https://github.com/apache/pulsar-client-go/pull/457


   ### Motivation
   
   For the present consumer, `Close()` and `Unsubscribe()` handled by the same 
eventloop goroutine.
   The eventloop exited after `Close()`, then unsubscribe event wouldn't be 
selected and handled anymore.
   
   example:
   ```go
   func main() {
        client, err := pulsar.NewClient(pulsar.ClientOptions{URL: 
"pulsar://localhost:6650"})
        if err != nil {
                log.Fatal(err)
        }
        defer client.Close()
   
        consumer, err := client.Subscribe(pulsar.ConsumerOptions{
                Topic:            "topic-1",
                SubscriptionName: "my-sub",
        })
        if err != nil {
                log.Fatal(err)
        }
        // blocked send event to eventloop channel since it never be selected 
anymore
        defer consumer.Unsubscribe() // unintentional
        defer consumer.Close()
   }
   ```
   
   `Unsubscribe()` blocked:
   
   
![image](https://user-images.githubusercontent.com/24536920/106294060-ab5d6b80-6289-11eb-913c-85e1d18467a0.png)
   
   
   
   
   ### Modifications
   
   Check consumer state before send unsubscribe event, if consumer is closing 
or has closed, just logging it
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.


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