Skip to content

Commit

Permalink
fix: concurrency issue in createAndInitValidators
Browse files Browse the repository at this point in the history
  • Loading branch information
jim380 committed Jan 5, 2024
1 parent 9d2dcea commit adda380
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (c *chain) createAndInitValidators(count int) error {
c.validators = make([]*validator, 0, count)

var wg sync.WaitGroup
var mu sync.Mutex // Mutex for synchronizing access to c.validators
errChan := make(chan error, count)

for i := 0; i < count; i++ {
Expand All @@ -79,7 +80,9 @@ func (c *chain) createAndInitValidators(count int) error {
return
}

mu.Lock() // Lock the mutex before appending to c.validators
c.validators = append(c.validators, node)
mu.Unlock() // Unlock the mutex after appending
}(i)
}

Expand Down

0 comments on commit adda380

Please sign in to comment.