github-vet / github-vet/rangeloop-pointer-findings
msoap/etc: docker-logs/docker-logs.go; 53 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [msoap/etc](https://www.github.com/msoap/etc) at [docker-logs/docker-logs.go](https://github.com/msoap/etc/blob/7fa19d46647cf677650b55034c08ae7ddc131146/docker-logs/docker-logs.go#L251-L303)
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 containerName used in defer or goroutine at line 272
[Click here to see the code in its original context.](https://github.com/msoap/etc/blob/7fa19d46647cf677650b55034c08ae7ddc131146/docker-logs/docker-logs.go#L251-L303)
Click here to show the 53 line(s) of Go which triggered the analyzer.
```go
for containerName, container := range app.containers {
if atomic.LoadInt32(container.outNum) > 0 {
continue
}
multiplexedLogReader, err := app.docker.ContainerLogs(app.ctx, container.id, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
Since: time.Now().Add(-sinceTimeSeconds * time.Second).Format(rfc3339LocalFormat),
})
if err != nil {
return err
}
atomic.StoreInt32(container.outNum, 2)
dstOutReader, dstOutWriter := io.Pipe()
dstErrReader, dstErrWriter := io.Pipe()
go func() {
closeStdErrFn := func() {
log.Printf("do close %q %s logs", containerName, outType(outTypeStdErr))
if err := dstErrWriter.Close(); err != nil {
log.Printf("close stderr for %q failed: %s", containerName, err)
}
}
if _, err := stdcopy.StdCopy(dstOutWriter, dstErrWriter, multiplexedLogReader); err != nil {
if err != io.EOF {
log.Printf("demultiplex %q via StdCopy failed: %q, try parse simple stdout", containerName, err)
closeStdErrFn()
// try parse out without headers
if _, err := io.Copy(dstOutWriter, multiplexedLogReader); err != nil {
if err == io.EOF {
log.Printf("%q logs closed", containerName)
} else {
log.Printf("copy %q logs failed: %s", containerName, err)
}
}
}
}
log.Printf("do close %q %s logs", containerName, outType(outTypeStdOut))
if err := dstOutWriter.Close(); err != nil {
log.Printf("close stdout for %q failed: %s", containerName, err)
}
closeStdErrFn()
}()
go app.processLogLines(logsCh, dstOutReader, containerName, outTypeStdOut)
go app.processLogLines(logsCh, dstErrReader, containerName, outTypeStdErr)
}
```
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: 7fa19d46647cf677650b55034c08ae7ddc131146
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with docker-logs/docker-logs.go lines 251-303 at commit 7fa19d46647cf677650b55034c08ae7ddc131146 and inspect the goroutine closures using containerName. Determine whether the analyzer finding represents a bug, mitigated issue, or desirable behavior, then leave the requested reaction classification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100