github-vet / github-vet/rangeloop-pointer-findings
fernandoantunes/whatsapp: conn.go; 28 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [fernandoantunes/whatsapp](https://www.github.com/fernandoantunes/whatsapp) at [conn.go](https://github.com/fernandoantunes/whatsapp/blob/c3e9e06d40fa3b3210dcd3887899405b1f0cf98e/conn.go#L366-L393)
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 msg used in defer or goroutine at line 390
[Click here to see the code in its original context.](https://github.com/fernandoantunes/whatsapp/blob/c3e9e06d40fa3b3210dcd3887899405b1f0cf98e/conn.go#L366-L393)
Click here to show the 28 line(s) of Go which triggered the analyzer.
```go
for msg := range wac.writeChan {
if !wac.connectionStatus.Connected() {
break
}
for !wac.isConnected() {
// reconnect to send the message ASAP
wac.wsConnMutex.Lock()
if wac.wsConn == nil {
if err := wac.connect(); err != nil {
fmt.Fprintf(os.Stderr, "could not reconnect to websocket: %v\n", err)
}
}
wac.wsConnMutex.Unlock()
if !wac.isConnected() {
// reconnecting failed. Sleep for a while and try again afterwards
time.Sleep(time.Duration(rand.Intn(5)) * time.Second)
}
}
if err := wac.wsConn.WriteMessage(msg.messageType, msg.data); err != nil {
fmt.Fprintf(os.Stderr, "error writing to socket: %v\n", err)
wac.wsConnOK = false
// add message to channel again to no loose it
go func() {
wac.writeChan <- msg
}()
}
}
```
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: c3e9e06d40fa3b3210dcd3887899405b1f0cf98e
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.