hoverseu opened a new issue, #1147:
URL: https://github.com/apache/rocketmq-client-go/issues/1147

   Once, we had a group that was not created, so our app code calling 
rocketmq.NewPushConsumer returned err. Since the retry mechanism, the method 
`rocketmq.NewPushConsumer` was called frequently, then we found that the memory 
kept growing.
   
   I speculated that there was groutine leak.  I use runtime.NumGoroutine() to 
print the number of groutines, which confirms this.
   
   By investigating the code and adding debug logs, we found that after calling 
pushConsumer.Shutdown(), some statistics-related goroutines could not exit in 
time and were blocked in sleep. The following are some of the blocking points. 
   
   1.  The first goroutine will block for 1 minute before returning. Even if 
sis.closed is closed.
   2. The send goroutine will block for 1 hour before returning. Even if 
sis.closed is closed.
   3. The third goroutine will block for 1 day before returning. Even if 
sis.closed is closed.
   
   
[consumer/statistics.go](https://github.com/apache/rocketmq-client-go/blob/9694e1c3900c65002b03af2e41f8dcb648bcc0c4/consumer/statistics.go#L173)
   `
   func (sis *statsItemSet) init() {
       ...
       // first goroutine 
        go primitive.WithRecover(func() {
                time.Sleep(nextMinutesTime().Sub(time.Now()))
                ticker := time.NewTicker(time.Minute)
                defer ticker.Stop()
                for {
                        select {
                        case <-sis.closed:
                                return
                        case <-ticker.C:
                                sis.printAtMinutes()
                        }
                }
        })
   
        // send goroutine 
        go primitive.WithRecover(func() {
                time.Sleep(nextHourTime().Sub(time.Now()))
                ticker := time.NewTicker(time.Hour)
                defer ticker.Stop()
                for {
                        select {
                        case <-sis.closed:
                                return
                        case <-ticker.C:
                                sis.printAtHour()
                        }
                }
        })
   
      // third goroutine
        go primitive.WithRecover(func() {
                time.Sleep(nextMonthTime().Sub(time.Now()))
                ticker := time.NewTicker(24 * time.Hour)
                defer ticker.Stop()
                for {
                        select {
                        case <-sis.closed:
                                return
                        case <-ticker.C:
                                sis.printAtDay()
                        }
                }
        })
   }
   `
   
   My advice:
   
   time.NewTicker will not be executed immediately, but after the Ticker cycle, 
so I think the sleep of these three routines is unnecessary.


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