github-vet / github-vet/rangeloop-pointer-findings
fractal-platform/fractal: ftl/network/handler.go; 55 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [fractal-platform/fractal](https://www.github.com/fractal-platform/fractal) at [ftl/network/handler.go](https://github.com/fractal-platform/fractal/blob/507b20d87e3b208d543404eeb358379a0232367f/ftl/network/handler.go#L973-L1027)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable block used in defer or goroutine at line 1003
[Click here to see the code in its original context.](https://github.com/fractal-platform/fractal/blob/507b20d87e3b208d543404eeb358379a0232367f/ftl/network/handler.go#L973-L1027)
Click here to show the 55 line(s) of Go which triggered the analyzer.
```go
for block := range pm.BlockProcessCh {
//log.Info("process block start", "index", index, "hash", block.Block.FullHash())
pm.blockProcessLock.Lock()
if !pm.blockProcessing.Contains(block.Block.FullHash()) && !pm.blockchain.HasBlock(block.Block.FullHash()) {
pm.blockProcessing.Add(block.Block.FullHash())
pm.blockProcessLock.Unlock()
var p *Peer
if block.Block.ReceivedFrom != nil {
p = block.Block.ReceivedFrom.(*Peer)
// Mark the peer as owning the block and schedule it for import
p.MarkBlock(block.Block.FullHash())
}
ok := pm.insertBlockInternal(p, block)
if ok {
// Update the peers head if better than the previous
var (
trueFullHash = block.Block.FullHash()
trueSimpleHash = block.Block.SimpleHash()
trueHeight = block.Block.Header.Height
trueRound = block.Block.Header.Round
)
if p.CompareTo(trueSimpleHash, trueHeight, trueRound) < 0 {
p.SetHead(trueFullHash, trueSimpleHash, trueHeight, trueRound)
}
// process future Blocks
go func() {
for _, futureBlock := range pm.blockchain.FutureBlocks(block.Block.FullHash()) {
pm.BlockProcessCh <- &BlockWithVerifyFlag{futureBlock, true}
log.Info("futureBlock", "Hash", futureBlock.FullHash(), "Height", futureBlock.Header.Height)
}
}()
pm.blockchain.RemoveFutureBlocks(block.Block.FullHash())
// process future tx packages
for _, futureTxPackage := range pm.blockchain.FutureBlockTxPackages(block.Block.FullHash()) {
log.Info("futureTxPackage", "pkgHash", futureTxPackage.Hash(), "blockHash", block.Block.FullHash())
if pm.insertTxPackage(futureTxPackage, true, true) {
pm.blockchain.RemoveFutureBlockTxPackage(futureTxPackage.Hash())
}
}
}
pm.blockProcessLock.Lock()
pm.blockProcessing.Remove(block.Block.FullHash())
pm.blockProcessLock.Unlock()
} else {
log.Debug("blockProcessLoop:have been in blockProcessing Set or in blockChain", "Hash", block.Block.FullHash(), "Height", block.Block.Header.Height)
pm.blockProcessLock.Unlock()
}
//log.Info("process block over", "index", index, "hash", block.Block.FullHash())
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 507b20d87e3b208d543404eeb358379a0232367f
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.