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

go-park-mail-ru/2019_1_SleeplessNights: game_microservice/game/game.go; 49 LoC

Open
#12,441 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 [go-park-mail-ru/2019_1_SleeplessNights](https://www.github.com/go-park-mail-ru/2019_1_SleeplessNights) at [game_microservice/game/game.go](https://github.com/go-park-mail-ru/2019_1_SleeplessNights/blob/45729e934ca0ae4cef7e111bd5d2816f15116be3/game_microservice/game/game.go#L21-L69)

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 p used in defer or goroutine at line 26

[Click here to see the code in its original context.](https://github.com/go-park-mail-ru/2019_1_SleeplessNights/blob/45729e934ca0ae4cef7e111bd5d2816f15116be3/game_microservice/game/game.go#L21-L69)

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

```go
for p := range in {

fmt.Println("Got value from channel")
logger.Info("Got new Player from channel g.in")
go func() {
err := p.Send(message.Message{Title: message.RoomSearching})
if err != nil {
logger.Warning("Failed to notify player with UID", p.UID())
}

logger.Info("goroutine Started:", "player UID", p.UID(), " looking for space room")
roomFound := false
for !roomFound {
roomsCounter := 0
roomFound = false
//Search for a player can join
for k, r := range g.rooms {
if r.KillMePleaseFlag == true {
logger.Info("Trying to delete Room k=", k, "r=", r)
// r.CloseResponseRequestChannels()
// delete(g.rooms, k)
logger.Info("Game, Room" + fmt.Sprint(k) + "was deleted from map")
} else {
if r.TryJoin(p) {
logger.Info("Found Existing , player UID ", p.UID(), " added")
roomFound = true
break
}
}
roomsCounter++
}
g.mu.Lock()
var roomId uint64
if roomsCounter != maxRooms && !roomFound {
g.idSource += 1
roomId = g.idSource
g.rooms[roomId] = &room.Room{}
roomFound = (g.rooms[roomId]).TryJoin(p)
}
g.mu.Unlock()
if roomFound {
logger.Info("Successfully found Room with id", roomId)
logger.Info("Player with UID", p.UID(), "added to room", roomId)
} else {
logger.Error("Failed to join just created Room with id", roomId)
}
}
}()
}

```

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: 45729e934ca0ae4cef7e111bd5d2816f15116be3

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.