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:
7 files changed
+33
-21
No files matched your search
@@ -78,13 +78,12 @@ func completePaymentRequests(client lnrpc.LightningClient,
|
||||
// Launch all payments simultaneously.
|
||||
results := make(chan error)
|
||||
for _, payReq := range paymentRequests {
|
||||
payReqCopy := payReq
|
||||
go func() {
|
||||
err := send(payReqCopy)
|
||||
go func(payReq string) {
|
||||
err := send(payReq)
|
||||
if awaitResponse {
|
||||
results <- err
|
||||
}
|
||||
}()
|
||||
}(payReq)
|
||||
}
|
||||
|
||||
// If awaiting a response, verify that all payments succeeded.
|
||||
|
||||
Reference in new issue
Block a user