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

funkygao/fae: servant/mysql/selector_standard.go; 34 LoC

Open
#9,657 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 [funkygao/fae](https://www.github.com/funkygao/fae) at [servant/mysql/selector_standard.go](https://github.com/funkygao/fae/blob/86d1d6200631e61cb4fc5d2bcb7ee61d9eda5816/servant/mysql/selector_standard.go#L25-L58)

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 server used in defer or goroutine at line 49

[Click here to see the code in its original context.](https://github.com/funkygao/fae/blob/86d1d6200631e61cb4fc5d2bcb7ee61d9eda5816/servant/mysql/selector_standard.go#L25-L58)

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

```go
for _, server := range cf.Servers {
my := newMysql(server.DSN(), cf.CachePrepareStmtMaxItems, &cf.Breaker)
for retries := uint(0); retries < cf.Breaker.FailureAllowance; retries++ {
log.Debug("mysql connecting: %s", server.DSN())

if my.Open() == nil && my.Ping() == nil {
// sql.Open() does not establish any connections to the database
// sql.Ping() does
break
}

my.breaker.Fail()
}

if !my.breaker.Open() {
my.db.SetMaxIdleConns(cf.MaxIdleConnsPerServer)
// TODO https://code.google.com/p/go/source/detail?r=8a7ac002f840
my.db.SetMaxOpenConns(cf.MaxConnsPerServer)
this.clients[server.Pool] = my

if cf.MaxIdleTime > 0 {
go func() {
for _ = range time.Tick(cf.MaxIdleTime) {
if err := my.Ping(); err != nil {
log.Error("mysql[%s]: %s", server.DSN(), err.Error())
my.breaker.Fail()
}

}
}()
}
}

}

```

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: 86d1d6200631e61cb4fc5d2bcb7ee61d9eda5816

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.