e3: worker stuck on exit (#6826)

This commit is contained in:
Alex Sharov 2023-02-10 13:18:39 +07:00 committed by GitHub
parent 0ebac009e7
commit 910ea64c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,7 +99,11 @@ func (rw *Worker) ResetTx(chainTx kv.Tx) {
func (rw *Worker) Run() {
for txTask, ok := rw.rs.Schedule(); ok; txTask, ok = rw.rs.Schedule() {
rw.RunTxTask(txTask)
rw.resultCh <- txTask // Needs to have outside of the lock
select {
case rw.resultCh <- txTask: // Needs to have outside of the lock
case <-rw.ctx.Done():
return
}
}
}
@ -310,6 +314,7 @@ func (cr EpochReader) FindBeforeOrEqualNumber(number uint64) (blockNum uint64, b
}
func NewWorkersPool(lock sync.Locker, ctx context.Context, background bool, chainDb kv.RoDB, rs *state.StateV3, blockReader services.FullBlockReader, chainConfig *chain.Config, logger log.Logger, genesis *core.Genesis, engine consensus.Engine, workerCount int) (reconWorkers []*Worker, applyWorker *Worker, resultCh chan *exec22.TxTask, clear func()) {
ctx, cancel := context.WithCancel(ctx)
var wg sync.WaitGroup
queueSize := workerCount * 2
reconWorkers = make([]*Worker, workerCount)
@ -319,11 +324,13 @@ func NewWorkersPool(lock sync.Locker, ctx context.Context, background bool, chai
}
applyWorker = NewWorker(lock, ctx, false, chainDb, rs, blockReader, chainConfig, logger, genesis, resultCh, engine)
clear = func() {
cancel()
wg.Wait()
for _, w := range reconWorkers {
w.ResetTx(nil)
}
applyWorker.ResetTx(nil)
close(resultCh)
}
if background {
wg.Add(workerCount)