github-vet / github-vet/rangeloop-pointer-findings

asyndrige/go-simple-dht: main.go; 17 LoC

Open
#15,226 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [asyndrige/go-simple-dht](https://www.github.com/asyndrige/go-simple-dht) at [main.go](https://github.com/asyndrige/go-simple-dht/blob/c3fccee920b4e80990b809ea2bb3282cb3160074/main.go#L155-L171)

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 addr used in defer or goroutine at line 160

[Click here to see the code in its original context.](https://github.com/asyndrige/go-simple-dht/blob/c3fccee920b4e80990b809ea2bb3282cb3160074/main.go#L155-L171)

Click here to show the 17 line(s) of Go which triggered the analyzer.

```go
for id, addr := range node.ht.data {
wg.Add(1)
go func(id uint16, mu *sync.WaitGroup) {
defer wg.Done()

conn, err := net.Dial("udp", addr)
if err != nil {
println(err.Error(), id)
return
}
_, err = conn.Write([]byte(fmt.Sprintf("%s %d %s", ping, node.ID, node.addr)))
if err != nil {
println(err.Error(), id)
return
}
}(id, wg)
}

```

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: c3fccee920b4e80990b809ea2bb3282cb3160074

Contributor guide

No contributing guide indexed for this repository

Research direction

Read main.go lines 155-171 at commit c3fccee920b4e80990b809ea2bb3282cb3160074, focusing on the reported range-loop variable use in the goroutine. Compare the snippet with the linked rangeclosure-findings classification guidance, then leave the reaction matching whether the finding is a bug, mitigated, or desirable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems, networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.