From 2ef5c67fd5f573821bf11c3221b46a14fefa9518 Mon Sep 17 00:00:00 2001 From: Vladislav Polskikh Date: Tue, 16 Jul 2024 10:50:47 +0200 Subject: [PATCH] Fix chain overfill when failed to get pk 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. --- cmd/convert/process.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/convert/process.go b/cmd/convert/process.go index 9678ce3..4f84f15 100644 --- a/cmd/convert/process.go +++ b/cmd/convert/process.go @@ -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()