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

devspace-cloud/devspace: pkg/devspace/services/log_manager.go; 40 LoC

Open
#14,701 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 [devspace-cloud/devspace](https://www.github.com/devspace-cloud/devspace) at [pkg/devspace/services/log_manager.go](https://github.com/devspace-cloud/devspace/blob/09876340af417c1c44d7804beb7a072ce812d504/pkg/devspace/services/log_manager.go#L98-L137)

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 t used in defer or goroutine at line 110

[Click here to see the code in its original context.](https://github.com/devspace-cloud/devspace/blob/09876340af417c1c44d7804beb7a072ce812d504/pkg/devspace/services/log_manager.go#L98-L137)

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

```go
for _, t := range targets {
_, ok := l.activeLogs[t.key]
if ok {
continue
}

splitted := strings.Split(t.key, "/")
namespace, pod, container := splitted[0], splitted[1], splitted[2]

logsContext, cancel := context.WithCancel(context.Background())
logsLog := log.NewPrefixLogger("["+t.name+"] ", log.Colors[(len(log.Colors)-1)-(len(l.activeLogs)%len(log.Colors))], l.output)
go func() {
logsLog.Infof("Start streaming logs for %s", t.key)
reader, err := l.client.Logs(logsContext, namespace, pod, container, false, &l.tail, true)
if err != nil {
logsLog.Warnf("Error streaming logs: %v", err)
}

if reader != nil {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
logsLog.Info(scanner.Text())
}
if scanner.Err() != nil && scanner.Err() != context.Canceled {
logsLog.Warnf("Error streaming logs for %s: %v", t.key, scanner.Err())
} else {
logsLog.Infof("End streaming logs for %s", t.key)
}
}

l.activeLogsMutex.Lock()
delete(l.activeLogs, t.key)
l.activeLogsMutex.Unlock()
}()

l.activeLogs[t.key] = activeLog{
cancelCtx: cancel,
log: logsLog,
}
}

```

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: 09876340af417c1c44d7804beb7a072ce812d504

Contributor guide

No contributing guide indexed for this repository

Research direction

Read pkg/devspace/services/log_manager.go around lines 98-137, starting with the goroutine launched inside the target range loop. Confirm the analyzer warning and check that each log stream still uses the intended target; done means the range-loop capture warning is resolved without changing log streaming behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.