zzzming opened a new pull request, #860:
URL: https://github.com/apache/pulsar-client-go/pull/860

   Fixes #859 
   
   Master Issue: #859
   
   ### Motivation
   
   The problem is basically WaitGroup does not allow Wait() and Add() to run 
concurrently. (Add() itself can run concurrently). This is clearly explained in 
the Go WaitGroup source code at 
https://github.com/golang/go/blob/master/src/sync/waitgroup.go#L30
   
   ```
   // Add adds delta, which may be negative, to the WaitGroup counter.
   // If the counter becomes zero, all goroutines blocked on Wait are released.
   // If the counter goes negative, Add panics.
   //
   // Note that calls with a positive delta that occur when the counter is zero
   // must happen before a Wait. Calls with a negative delta, or calls with a
   // positive delta that start when the counter is greater than zero, may 
happen
   // at any time.
   // Typically this means the calls to Add should execute before the statement
   // creating the goroutine or other event to be waited for.
   ```
   
   ### Modifications
   
   The WaitGroup, incomingRequestsWG, in the connection.go waits all the sent 
requests before close the main run goroutine. The design is for run() wait for 
any requests to be completed if there is any. So both Wait() and Add() are in 
this concurrent manner. The code should preemptively Add(1) before Wait() is 
called in the closeCh triggered.
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (no)
     - The schema: ( no )
     - The default values of configurations: ( no)
     - The wire protocol: (no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (/ no)
     - If yes, how is the feature documented? (not applicable )
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup 
issue for adding the documentation
   


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