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

TassiloKloos/ObserverProject: observer.go; 56 LoC

Open
#17,578 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 [TassiloKloos/ObserverProject](https://www.github.com/TassiloKloos/ObserverProject) at [observer.go](https://github.com/TassiloKloos/ObserverProject/blob/3dbf53367fb0dcb910cb8e2c753776ba6fb5f49e/observer.go#L114-L169)

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 processNR used in defer or goroutine at line 118

[Click here to see the code in its original context.](https://github.com/TassiloKloos/ObserverProject/blob/3dbf53367fb0dcb910cb8e2c753776ba6fb5f49e/observer.go#L114-L169)

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

```go
for processNR := range runningProcesses { //überprüfen, ob Prozess noch läuft; automaticRestart/restartCounter beachten

channel := make(chan error, 1)
go func() {
channel <- runningProcesses[processNR].Wait()
}()
select { // die Idee einen select mit Timeout auf den Channel zu machen stammt von Oliver Raum, der Code wurde ohne seine Hilfe erstellt
case err := <-channel:
if err != nil {
err = nil
}
case <-time.After(100000000): // 0,1 sec wait
// wartet nicht auf beenden vom channel
}

//try catch Funktion hier für
func() {
defer func() {
if r := recover(); r != nil {
//Catch hier
stopProcessButtons = stopProcessButtons + "" +
"" +
""
}
}()
//Try hier
if runningProcesses[processNR].ProcessState.Exited() == true && automaticRestart[processNR] == true {
cmd := exec.Command(availableApps[availableAppsNumberForCmd[processNR]])

stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
} else {
stdinPipes[processNR] = stdin
}

stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
reader := bufio.NewReader(stdout)
cmd.Start()
line, _, _ := reader.ReadLine()
stdOutput = append(stdOutput, string(line))
runningProcesses[processNR] = cmd
restartCounter[availableAppsNumberForCmd[processNR]]++
stopProcessButtons = stopProcessButtons + "" +
"" +
""
} else if runningProcesses[processNR].ProcessState.Exited() == false {
stopProcessButtons = stopProcessButtons + "" +
"" +
""
}
}()
}

```

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: 3dbf53367fb0dcb910cb8e2c753776ba6fb5f49e

Contributor guide

No contributing guide indexed for this repository

Research direction

Read observer.go at lines 114-169 in commit 3dbf53367fb0dcb910cb8e2c753776ba6fb5f49e, starting with the goroutine that uses processNR. Check the surrounding range-loop behavior and determine whether the analyzer finding is a Bug, Mitigated, or Desirable Behavior. Record the classification with the corresponding reaction on the issue.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.