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

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

Open
#14,770 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/eaf37e0aff2659bb1c9995f80faac125efa510d7/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/eaf37e0aff2659bb1c9995f80faac125efa510d7/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, 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: eaf37e0aff2659bb1c9995f80faac125efa510d7

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.