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

terra-project/mantle-sdk: graph/local_run.go; 59 LoC

Open
#16,831 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 [terra-project/mantle-sdk](https://www.github.com/terra-project/mantle-sdk) at [graph/local_run.go](https://github.com/terra-project/mantle-sdk/blob/c4df7e5a2bc83b9712042bed95635caca461a3b6/graph/local_run.go#L57-L115)

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 selection used in defer or goroutine at line 61

[Click here to see the code in its original context.](https://github.com/terra-project/mantle-sdk/blob/c4df7e5a2bc83b9712042bed95635caca461a3b6/graph/local_run.go#L57-L115)

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

```go
for _, selection := range querySelections {
go func() {
defer wg.Done()

switch selection := selection.(type) {
case *ast.Field:
fieldName := selection.Name
fieldConfig := fields[fieldName.Value]

var variables = make(map[string]interface{})

// map arguments to query arguments
if len(selection.Arguments) > 0 {
for _, argument := range selection.Arguments {
argumentName := argument.Name.Value
switch argumentValue := argument.Value.GetValue().(type) {
case *ast.Name:
variables[argumentName] = p.VariableValues[argumentValue.Value]
case ast.Variable:
variables[argumentName] = p.VariableValues[argumentValue.Name.Value]
default:
variables[argumentName] = argumentValue
}
}
}

rp := graphql.ResolveParams{
Source: source,
Args: variables,
Info: graphql.ResolveInfo{},
Context: p.Context,
}

// mutex control
sync.Lock()
defer sync.Unlock()

result, err := unthunkResult(fieldConfig.Resolve(rp))

if err != nil {
gqlRunResult.Errors = []error{err}
return
}

pack, packErr := serdes.Serialize(nil, result)
if packErr != nil {
gqlRunResult.Errors = []error{err}
return
}

// save
gqlRunResult.Data[fieldName.Value] = pack
return

case *ast.FragmentDefinition:
// noop yet
}
}()
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at graph/local_run.go, lines 57-115, and inspect the range loop and goroutine around line 61. Compare the analyzer warning with the shown use of selection, then classify the finding as a bug, mitigated issue, or desirable behavior; done means the classification is supported by the code.

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.