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

gamedb/gamedb: pkg/queue/app_players.go; 108 LoC

Open
#18,359 0 comments 0 reactions 0 assignees View on GitHub
fresh large
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [gamedb/gamedb](https://www.github.com/gamedb/gamedb) at [pkg/queue/app_players.go](https://github.com/gamedb/gamedb/blob/0cf67cf2879af7b1f100d6ae44de0d3f8b96df54/pkg/queue/app_players.go#L46-L153)

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 app used in defer or goroutine at line 58

[Click here to see the code in its original context.](https://github.com/gamedb/gamedb/blob/0cf67cf2879af7b1f100d6ae44de0d3f8b96df54/pkg/queue/app_players.go#L46-L153)

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

```go
for _, app := range apps {

var wg sync.WaitGroup

// Reads
wg.Add(1)
var twitchViewers int
go func() {

defer wg.Done()

var err error
twitchViewers, err = getAppTwitchStreamers(app.TwitchID)
if err != nil {

if strings.Contains(err.Error(), "read: connection reset by peer") ||
strings.Contains(err.Error(), "i/o timeout") ||
strings.Contains(err.Error(), "unexpected EOF") {
log.InfoS(err, payload.IDs)
} else {
log.ErrS(err, payload.IDs)
}

sendToRetryQueue(message)
return
}
}()

wg.Add(1)
var inGame int
go func() {

defer wg.Done()

var err error
inGame, err = getAppOnlinePlayers(app.ID)
if err != nil {
steam.LogSteamError(err, zap.Ints("app ids", payload.IDs))
sendToRetryQueue(message)
return
}
}()

wg.Wait()

if message.ActionTaken {
continue
}

// Save counts to Influx
wg.Add(1)
go func() {

defer wg.Done()

err = saveAppPlayerToInflux(app.ID, twitchViewers, inGame)
if err != nil {
log.ErrS(err, payload.IDs)
sendToRetryQueue(message)
return
}
}()

// Update app row
if inGame > app.PlayerPeakAllTime {

wg.Add(1)
go func() {

defer wg.Done()

filter := bson.D{{"_id", app.ID}}
update := bson.D{
{"player_peak_alltime", inGame},
{"player_peak_alltime_time", time.Now()},
}

_, err = mongo.UpdateOne(mongo.CollectionApps, filter, update)
if err != nil {
log.ErrS(err, app.ID)
sendToRetryQueue(message)
return
}

// Clear cache
err = memcache.Delete(memcache.MemcacheApp(app.ID).Key)
if err != nil {
log.ErrS(err, app.ID)
sendToRetryQueue(message)
return
}

// Update in Elastic
err = ProduceAppSearch(nil, app.ID)
if err != nil {
log.ErrS(err, app.ID)
sendToRetryQueue(message)
return
}
}()
}

wg.Wait()

if message.ActionTaken {
continue
}
}

```

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: 0cf67cf2879af7b1f100d6ae44de0d3f8b96df54

Contributor guide

No contributing guide indexed for this repository

Research direction

Review pkg/queue/app_players.go, especially the range over apps and the goroutines that use app. Start by checking the analyzer's range-loop capture finding against the shown code and the referenced commit. Done means leaving the requested reaction classifying the finding as Bug, Mitigated, or Desirable 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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.