From 61fa179dd5833e4434fbfe7558fcbb695e5fb148 Mon Sep 17 00:00:00 2001 From: islishude Date: Sat, 1 Feb 2020 10:08:21 +0800 Subject: [PATCH] account: fix timer leak --- accounts/usbwallet/wallet.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index ee539d9653..5388074fa9 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -185,13 +185,16 @@ func (w *wallet) heartbeat() { errc chan error err error ) + + timer := time.NewTicker(heartbeatCycle) + defer timer.Stop() for errc == nil && err == nil { // Wait until termination is requested or the heartbeat cycle arrives select { case errc = <-w.healthQuit: // Termination requested continue - case <-time.After(heartbeatCycle): + case <-timer.C: // Heartbeat time } // Execute a tiny data exchange to see responsiveness