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

materials-commons/mc: internal/file/background_loader.go; 37 LoC

Open
#17,016 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 [materials-commons/mc](https://www.github.com/materials-commons/mc) at [internal/file/background_loader.go](https://github.com/materials-commons/mc/blob/e37fe638d79b52c4c32492f696578b1b650d17e0/internal/file/background_loader.go#L59-L95)

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 req used in defer or goroutine at line 93

[Click here to see the code in its original context.](https://github.com/materials-commons/mc/blob/e37fe638d79b52c4c32492f696578b1b650d17e0/internal/file/background_loader.go#L59-L95)

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

```go
for _, req := range requests {

if req.Loading {
// This request is already being processed so ignore it
continue
}

// Check if project is already being processed
if _, ok := l.activeProjects.Load(req.ProjectID); ok {
// There is already a load active for this project, so skip
// processing this load request
continue
}

// If we are here then the current request is not being processed
// and it is for a project that is *not* currently being processed.

log.Infof("processing request %#v\n", req)

// Mark job as loading so we won't attempt to load this request a second time
if err := fileloadsStore.UpdateLoading(req.ID, true); err != nil {
// If the job cannot be marked as loading then skip processing it
log.Infof("Unable to update file load request %s: %s", req.ID, err)
continue
}

// Lock the project so no other uploads for this project will be processed. This is
// done to prevent issues such as checks and writes to the database creating two entries.
l.activeProjects.Store(req.ProjectID, true)

// pool.Process() is synchronous, so run in separate routine and let the pool control
// how many jobs are running simultaneously.
go func() {
// pool.Process will call the worker function (below) for processing the request
pool.Process(req)
}()
}

```

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

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.