Skip to content

Commit

Permalink
Fix chain overfill when failed to get pk
Browse files Browse the repository at this point in the history
If we overfill the chain the runtime will deadlock between wgA.Wait()
and pushing to the aPKMap chain.
I'd suggest to pushing to the chain only in one place in the goroutine
to exclude the overfilling case.
  • Loading branch information
polskikh committed Jul 16, 2024
1 parent 380f9ee commit 2ef5c67
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/convert/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ func process(data *dataIn) error {
wgA.Add(1)
go func(aName string, wName string) {
defer wgA.Done()
var aPK a
// Get Private Key From Account
utils.Log.Info().Msgf("getting private key for account %s from wallet %s", aName, wName)
pk, err := iStore.GetPK(wName, aName)
if err != nil {
aPKMap <- a{name: aName, pk: []byte{}, err: err, wName: wName}
utils.Log.Error().Err(err).Msgf("failed to get private key for account %s from wallet %s", aName, wName)
aPK = a{name: aName, pk: []byte{}, err: err, wName: wName}
} else {
utils.Log.Info().Msgf("got private key for account %s from wallet %s", aName, wName)
aPK = a{name: aName, pk: pk, err: nil, wName: wName}
}
aPKMap <- a{name: aName, pk: pk, err: nil, wName: wName}
aPKMap <- aPK
}(acc.Name, acc.WName)
}
wgA.Wait()
Expand Down

0 comments on commit 2ef5c67

Please sign in to comment.