mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
use tickers instead of time.After to avoid memory leak (#5220)
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
@@ -92,8 +92,10 @@ func (d *dio) write(payload *tap.Dnstap) error {
|
||||
}
|
||||
|
||||
func (d *dio) serve() {
|
||||
timeout := time.After(d.flushTimeout)
|
||||
timeout := time.NewTimer(d.flushTimeout)
|
||||
defer timeout.Stop()
|
||||
for {
|
||||
timeout.Reset(d.flushTimeout)
|
||||
select {
|
||||
case <-d.quit:
|
||||
if d.enc == nil {
|
||||
@@ -106,7 +108,7 @@ func (d *dio) serve() {
|
||||
if err := d.write(&payload); err != nil {
|
||||
d.dial()
|
||||
}
|
||||
case <-timeout:
|
||||
case <-timeout.C:
|
||||
if dropped := atomic.SwapUint32(&d.dropped, 0); dropped > 0 {
|
||||
log.Warningf("Dropped dnstap messages: %d", dropped)
|
||||
}
|
||||
@@ -115,7 +117,6 @@ func (d *dio) serve() {
|
||||
} else {
|
||||
d.enc.flush()
|
||||
}
|
||||
timeout = time.After(d.flushTimeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user