diff --git a/blockchain/blockdao/blockindexer.go b/blockchain/blockdao/blockindexer.go index 6c698917e5..59c8cbd1fb 100644 --- a/blockchain/blockdao/blockindexer.go +++ b/blockchain/blockdao/blockindexer.go @@ -82,6 +82,10 @@ func (bic *BlockIndexerChecker) CheckIndexer(ctx context.Context, indexer BlockI } } for i := startHeight; i <= targetHeight; i++ { + // ternimate if context is done + if err := ctx.Err(); err != nil { + return errors.Wrap(err, "terminate the indexer checking") + } blk, err := bic.dao.GetBlockByHeight(i) if err != nil { return err diff --git a/server/itx/server.go b/server/itx/server.go index 8cd215ccba..b1296fc200 100644 --- a/server/itx/server.go +++ b/server/itx/server.go @@ -113,7 +113,7 @@ func newServer(cfg config.Config, testing bool) (*Server, error) { // Start starts the server func (s *Server) Start(ctx context.Context) error { - cctx, cancel := context.WithCancel(context.Background()) + cctx, cancel := context.WithCancel(ctx) s.subModuleCancel = cancel for id, cs := range s.chainservices { if err := cs.Start(cctx); err != nil {