apache / pulsar-client-go

Apache Pulsar Go Client Library
https://pulsar.apache.org/
Apache License 2.0
652 stars 335 forks source link

Readers leak timers when closed #1262

Closed MishimaPorte closed 3 weeks ago

MishimaPorte commented 2 months ago

Expected behavior

Readers should call ticker.Stop() on timedAckGroupingTracker when they are closed (e.g. when a reader is closed).

Actual behavior

The ticker.Stop method is never called on the timedAckGroupingTracker member ticker, and so it is leaked.

Steps to reproduce

Create and close a substantial amount of Reader instances (using client.CreateReader()). After a substantial amount of Tickers is leaked, you will notice massive performance penalties due to go runtime's handling of all the leaked tickers and increasing amounts of Ticker objects allocated (the picture is from the standard go pprof tool, showing 90Mb of Ticker objects allocated).

the_bad

System configuration

Pulsar version: 2.10

geniusjoe commented 3 weeks ago

@MishimaPorte Do you mean we need some code snippet like below?

func (t *timedAckGroupingTracker) close() {
    t.flushAndClean()
    if t.exitCh != nil {
        close(t.exitCh)
    }
    if t.ticker != nil {
        t.ticker.Stop()
    }
}