From d3e4e30ac9ce1f787d108ef6fa1c6b6fb14a4f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Thu, 3 May 2018 10:42:59 +0200 Subject: [PATCH] swarm/network/stream: fix syncer ticker leak (#485) * swarm/network/stream: fix syncer ticker leak * swarm/network/stream: a better ticker stop for syncer SetNextBatch --- swarm/network/stream/syncer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/swarm/network/stream/syncer.go b/swarm/network/stream/syncer.go index 68e658e68521..3bf55dfdaf30 100644 --- a/swarm/network/stream/syncer.go +++ b/swarm/network/stream/syncer.go @@ -98,6 +98,11 @@ func (s *SwarmSyncerServer) SetNextBatch(from, to uint64) ([]byte, uint64, uint6 to = math.MaxUint64 } var ticker *time.Ticker + defer func() { + if ticker != nil { + ticker.Stop() + } + }() var wait bool for { if wait { @@ -124,9 +129,6 @@ func (s *SwarmSyncerServer) SetNextBatch(from, to uint64) ([]byte, uint64, uint6 } wait = true } - if wait { - ticker.Stop() - } log.Trace("Swarm syncer offer batch", "po", s.po, "len", i, "from", from, "to", to, "current store count", s.db.CurrentBucketStorageIndex(s.po)) return batch, from, to, nil, nil