From 05e5b05be1f6516deb1d148551cc96de68e97eeb Mon Sep 17 00:00:00 2001 From: notanatol Date: Fri, 21 Jul 2023 21:19:32 +0300 Subject: [PATCH] fix: revert pullsync --- pkg/pullsync/pullsync.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/pullsync/pullsync.go b/pkg/pullsync/pullsync.go index 2a7d2b2e4a8..550a2deeefb 100644 --- a/pkg/pullsync/pullsync.go +++ b/pkg/pullsync/pullsync.go @@ -27,7 +27,6 @@ import ( "github.com/ethersphere/bee/pkg/storage" storer "github.com/ethersphere/bee/pkg/storer" "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util" "resenje.org/multex" "resenje.org/singleflight" ) @@ -86,7 +85,6 @@ type Syncer struct { intervalsSF singleflight.Group syncInProgress atomic.Int32 binLock *multex.Multex - inFlight *util.WaitingCounter maxPage uint64 @@ -113,7 +111,6 @@ func New( quit: make(chan struct{}), maxPage: maxPage, binLock: multex.New(), - inFlight: new(util.WaitingCounter), } } @@ -560,10 +557,22 @@ func (s *Syncer) cursorHandler(ctx context.Context, p p2p.Peer, stream p2p.Strea func (s *Syncer) Close() error { s.logger.Info("pull syncer shutting down") close(s.quit) + cc := make(chan struct{}) + go func() { + defer close(cc) + for { + if s.syncInProgress.Load() > 0 { + time.Sleep(100 * time.Millisecond) + continue + } + break + } + }() - if rgr := s.inFlight.Wait(5 * time.Second); rgr > 0 { + select { + case <-cc: + case <-time.After(5 * time.Second): s.logger.Warning("pull syncer shutting down with running goroutines") } - return nil }