correct iterate over items when goroutine inside loop (#2219)

This commit is contained in:
Alex Sharov 2021-06-22 20:33:22 +07:00 committed by GitHub
parent 59d05dc5fe
commit 24a76a002d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -641,8 +641,12 @@ func (s *Ethereum) Protocols() []p2p.Protocol {
// Ethereum protocol implementation.
func (s *Ethereum) Start() error {
for i := range s.sentries {
go download.RecvMessageLoop(s.downloadV2Ctx, s.sentries[i], s.downloadServer, nil)
go download.RecvUploadMessageLoop(s.downloadV2Ctx, s.sentries[i], s.downloadServer, nil)
go func(i int) {
download.RecvMessageLoop(s.downloadV2Ctx, s.sentries[i], s.downloadServer, nil)
}(i)
go func(i int) {
download.RecvUploadMessageLoop(s.downloadV2Ctx, s.sentries[i], s.downloadServer, nil)
}(i)
}
go Loop(s.downloadV2Ctx, s.chainKV, s.stagedSync2, s.downloadServer, s.events, s.config.StateStream, s.waitForStageLoopStop)

View File

@ -311,8 +311,10 @@ func NewStagedSync2(
stagedsync.StageCallTracesCfg(db, 0, batchSize, tmpdir, controlServer.ChainConfig, controlServer.Engine),
stagedsync.StageTxLookupCfg(db, tmpdir),
stagedsync.StageTxPoolCfg(db, txPool, func() {
for _, s := range txPoolServer.Sentries {
go txpool.RecvTxMessageLoop(ctx, s, controlServer, txPoolServer.HandleInboundMessage, nil)
for i := range txPoolServer.Sentries {
go func(i int) {
txpool.RecvTxMessageLoop(ctx, txPoolServer.Sentries[i], controlServer, txPoolServer.HandleInboundMessage, nil)
}(i)
}
txPoolServer.TxFetcher.Start()
}),