Cancel Initial Sync Properly (#5529)

* fix cancelling
* Merge branch 'master' into cancelServices
* Merge refs/heads/master into cancelServices
* Merge refs/heads/master into cancelServices
This commit is contained in:
Nishant Das
2020-04-20 12:04:45 +08:00
committed by GitHub
parent 984644257e
commit 639e3072fe
3 changed files with 40 additions and 32 deletions

View File

@@ -47,6 +47,7 @@ type Config struct {
// Service service.
type Service struct {
ctx context.Context
cancel context.CancelFunc
chain blockchainService
p2p p2p.P2P
db db.ReadOnlyDatabase
@@ -60,8 +61,10 @@ type Service struct {
// NewInitialSync configures the initial sync service responsible for bringing the node up to the
// latest head of the blockchain.
func NewInitialSync(cfg *Config) *Service {
ctx, cancel := context.WithCancel(context.Background())
return &Service{
ctx: context.Background(),
ctx: ctx,
cancel: cancel,
chain: cfg.Chain,
p2p: cfg.P2P,
db: cfg.DB,
@@ -157,6 +160,7 @@ func (s *Service) Start() {
// Stop initial sync.
func (s *Service) Stop() error {
s.cancel()
return nil
}