multi: don't access loop variables in goroutines

This commit makes sure that no loop variables or other temporary
variables are accessed directly in a goroutine but are instead passed
into the goroutine through a parameter. This makes sure a copy of the
value is put on the stack and is not changed while the outside loop
continues.
This commit is contained in:
Oliver Gugger committed 2022-11-21 13:54:23 +01:00
1 parent e7170ef819
commit ad8e25cbc9
7 files changed
+33 -21

No files matched your search

+8 -4
View File
@@ -235,7 +235,9 @@ out:
//
// TODO(wilmer): add retry logic if rescan fails?
b.wg.Add(1)
go func() {
//nolint:lll
go func(msg *chainntnfs.HistoricalConfDispatch) {
defer b.wg.Done()
confDetails, _, err := b.historicalConfDetails(
@@ -269,7 +271,7 @@ out:
"details of %v: %v",
msg.ConfRequest, err)
}
}()
}(msg)
case *chainntnfs.HistoricalSpendDispatch:
// In order to ensure we don't block the caller
@@ -278,7 +280,9 @@ out:
//
// TODO(wilmer): add retry logic if rescan fails?
b.wg.Add(1)
go func() {
//nolint:lll
go func(msg *chainntnfs.HistoricalSpendDispatch) {
defer b.wg.Done()
spendDetails, err := b.historicalSpendDetails(
@@ -320,7 +324,7 @@ out:
"details of %v: %v",
msg.SpendRequest, err)
}
}()
}(msg)
case *blockEpochRegistration:
chainntnfs.Log.Infof("New block epoch subscription")
+4 -2
View File
@@ -347,7 +347,9 @@ out:
//
// TODO(wilmer): add retry logic if rescan fails?
b.wg.Add(1)
go func() {
//nolint:lll
go func(msg *chainntnfs.HistoricalConfDispatch) {
defer b.wg.Done()
confDetails, _, err := b.historicalConfDetails(
@@ -372,7 +374,7 @@ out:
if err != nil {
chainntnfs.Log.Error(err)
}
}()
}(msg)
case *blockEpochRegistration:
chainntnfs.Log.Infof("New block epoch subscription")
+4 -2
View File
@@ -432,7 +432,9 @@ func (n *NeutrinoNotifier) notificationDispatcher() {
// chain asynchronously to prevent blocking
// potentially long rescans.
n.wg.Add(1)
go func() {
//nolint:lll
go func(msg *chainntnfs.HistoricalConfDispatch) {
defer n.wg.Done()
confDetails, err := n.historicalConfDetails(
@@ -457,7 +459,7 @@ func (n *NeutrinoNotifier) notificationDispatcher() {
if err != nil {
chainntnfs.Log.Error(err)
}
}()
}(msg)
case *blockEpochRegistration:
chainntnfs.Log.Infof("New block epoch subscription")