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

ByteArena/ba: subcommand/train/main.go; 78 LoC

Open
#10,665 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 [ByteArena/ba](https://www.github.com/ByteArena/ba) at [subcommand/train/main.go](https://github.com/ByteArena/ba/blob/d53ef707e1f92c928fb1b2af412b4c03b5b2d364/subcommand/train/main.go#L157-L234)

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 agentPath used in defer or goroutine at line 200

[Click here to see the code in its original context.](https://github.com/ByteArena/ba/blob/d53ef707e1f92c928fb1b2af412b4c03b5b2d364/subcommand/train/main.go#L157-L234)

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

```go
for _, agentPath := range args.WatchedAgentimages {

// build for the first time
_, buildErr := build.Main(agentPath, build.Arguments{})

if buildErr != nil {
berror := bettererrors.
New("Failed to build agent").
With(buildErr)

utils.FailWith(berror)
}

watcher, watcherr := watcher.MakeWatcher()

if watcherr != nil {
return DONT_SHOW_USAGE, bettererrors.NewFromErr(err)
}

// Get image name from agent manifest file
agentManifest, parseManifestError := types.ParseAgentManifestFromDir(agentPath)

if parseManifestError != nil {
return DONT_SHOW_USAGE, bettererrors.
New("Could not parse manifest").
With(parseManifestError)
}

dockerImageName := agentManifest.Id

agentManifest, err := types.GetAgentManifestByDockerImageName(dockerImageName, orchestrator)
if err != nil {
return DONT_SHOW_USAGE, err
}

agent := &types.Agent{Manifest: agentManifest}

gamedescription.AddAgent(agent)
srv.RegisterAgent(agent, nil)

go func() {
defer watcher.Close()

watcher.Add(agentPath)

for {
watcherErr := <-watcher.Wait()

if watcherErr != nil {
utils.FailWith(watcherErr)
return
}

_, buildErr := build.Main(agentPath, build.Arguments{})

if buildErr != nil {
berror := bettererrors.
New("Failed to build agent").
With(buildErr)

utils.FailWith(berror)
}

fmt.Printf("Awaiting changes in %s ...\n", agentPath)

reloadErr := srv.ReloadAgent(agent)

if reloadErr != nil {
berror := bettererrors.
New("Could not reload agent").
With(reloadErr)

utils.FailWith(berror)
return
}
}
}()
}

```

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: d53ef707e1f92c928fb1b2af412b4c03b5b2d364

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.