Merge pull request #19 from zplzpl/hotfix/tickerStop

Possible memory leak because of Ticker
This commit is contained in:
Andy Pan 2018-12-01 23:49:31 +08:00 committed by GitHub
commit 639f55c4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -62,6 +62,8 @@ type Pool struct {
// clear expired workers periodically. // clear expired workers periodically.
func (p *Pool) periodicallyPurge() { func (p *Pool) periodicallyPurge() {
heartbeat := time.NewTicker(p.expiryDuration) heartbeat := time.NewTicker(p.expiryDuration)
defer heartbeat.Stop()
for range heartbeat.C { for range heartbeat.C {
currentTime := time.Now() currentTime := time.Now()
p.lock.Lock() p.lock.Lock()

View File

@ -63,6 +63,8 @@ type PoolWithFunc struct {
// clear expired workers periodically. // clear expired workers periodically.
func (p *PoolWithFunc) periodicallyPurge() { func (p *PoolWithFunc) periodicallyPurge() {
heartbeat := time.NewTicker(p.expiryDuration) heartbeat := time.NewTicker(p.expiryDuration)
defer heartbeat.Stop()
for range heartbeat.C { for range heartbeat.C {
currentTime := time.Now() currentTime := time.Now()
p.lock.Lock() p.lock.Lock()