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

stephane-martin/skewer: services/network/udp.go; 62 LoC

Open
#6,281 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [stephane-martin/skewer](https://www.github.com/stephane-martin/skewer) at [services/network/udp.go](https://github.com/stephane-martin/skewer/blob/2081a449f6b40c02ee2009caf9c165da9a3dd260/services/network/udp.go#L181-L242)

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 syslogConf used in defer or goroutine at line 202

[Click here to see the code in its original context.](https://github.com/stephane-martin/skewer/blob/2081a449f6b40c02ee2009caf9c165da9a3dd260/services/network/udp.go#L181-L242)

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

```go
for _, syslogConf := range s.UdpConfigs {
if len(syslogConf.UnixSocketPath) > 0 {
conn, err := s.Binder.ListenPacket("unixgram", syslogConf.UnixSocketPath, 65536)
if err != nil {
s.Logger.Warn("Listen unixgram error", "error", err)
continue
}
s.Logger.Debug(
"Unixgram listener",
"protocol", "udp",
"path", syslogConf.UnixSocketPath,
"format", syslogConf.Format,
)
c <- model.ListenerInfo{
UnixSocketPath: syslogConf.UnixSocketPath,
Protocol: "udp",
}
s.UnixSocketPaths = append(s.UnixSocketPaths, syslogConf.UnixSocketPath)
wg.Add(1)
go func() {
defer wg.Done()
err := s.handleConnection(conn, syslogConf)
if err != nil && !eerrors.HasFileClosed(err) {
s.Logger.Warn("Unix datagram connection error", "error", err)
}
}()
} else {
listenAddrs, err := syslogConf.GetListenAddrs()
if err != nil {
s.Logger.Warn("Error getting listening address for UDP connection", "error", err)
continue
}
L:
for port, listenAddr := range listenAddrs {
conn, err := s.Binder.ListenPacket("udp", listenAddr, 65536)
if err != nil {
s.Logger.Warn("Listen UDP error", "error", err)
continue L
}
s.Logger.Debug(
"UDP listener",
"protocol", "udp",
"bind_addr", syslogConf.BindAddr,
"port", port,
"format", syslogConf.Format,
)
c <- model.ListenerInfo{
BindAddr: syslogConf.BindAddr,
Port: port,
Protocol: "udp",
}
wg.Add(1)
go func() {
defer wg.Done()
err := s.handleConnection(conn, syslogConf)
if err != nil && !eerrors.HasFileClosed(err) {
s.Logger.Warn("UDP connection error", "error", err)
}
}()
}
}
}

```

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: 2081a449f6b40c02ee2009caf9c165da9a3dd260

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.