github-vet / github-vet/rangeloop-pointer-findings
wanglg007/etcd: embed/etcd.go; 69 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [wanglg007/etcd](https://www.github.com/wanglg007/etcd) at [embed/etcd.go](https://github.com/wanglg007/etcd/blob/dc8016287344ee6ece572a1c3f1fdf6a6525ce9d/embed/etcd.go#L406-L474)
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 u used in defer or goroutine at line 460
[Click here to see the code in its original context.](https://github.com/wanglg007/etcd/blob/dc8016287344ee6ece572a1c3f1fdf6a6525ce9d/embed/etcd.go#L406-L474)
Click here to show the 69 line(s) of Go which triggered the analyzer.
```go
for _, u := range cfg.LCUrls {
sctx := newServeCtx() //每个Client URL都对应一个serveCtx实例
if u.Scheme == "http" || u.Scheme == "unix" {
if !cfg.ClientTLSInfo.Empty() {
plog.Warningf("The scheme of client url %s is HTTP while peer key/cert files are presented. Ignored key/cert files.", u.String())
}
if cfg.ClientTLSInfo.ClientCertAuth {
plog.Warningf("The scheme of client url %s is HTTP while client cert auth (--client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String())
}
}
if (u.Scheme == "https" || u.Scheme == "unixs") && cfg.ClientTLSInfo.Empty() {
return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String())
}
proto := "tcp"
addr := u.Host
if u.Scheme == "unix" || u.Scheme == "unixs" {
proto = "unix"
addr = u.Host + u.Path
}
sctx.secure = u.Scheme == "https" || u.Scheme == "unixs"
sctx.insecure = !sctx.secure
if oldctx := sctxs[addr]; oldctx != nil {
oldctx.secure = oldctx.secure || sctx.secure
oldctx.insecure = oldctx.insecure || sctx.insecure
continue
}
if sctx.l, err = net.Listen(proto, addr); err != nil { //创建Listener
return nil, err
}
// net.Listener will rewrite ipv4 0.0.0.0 to ipv6 [::], breaking
// hosts that disable ipv6. So, use the address given by the user.
sctx.addr = addr //更新addr字段
if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil { //根据不同的系统和协议,对sctx.1中记录的Listener进行调整
if fdLimit <= reservedInternalFDNum {
plog.Fatalf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum)
}
sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum))
}
if proto == "tcp" {
if sctx.l, err = transport.NewKeepAliveListener(sctx.l, "tcp", nil); err != nil {
return nil, err
}
}
plog.Info("listening for client requests on ", u.Host)
defer func() {
if err != nil {
sctx.l.Close()
plog.Info("stopping listening for client requests on ", u.Host)
}
}()
for k := range cfg.UserHandlers { //设置用户自定义的Handler
sctx.userHandlers[k] = cfg.UserHandlers[k]
}
sctx.serviceRegister = cfg.ServiceRegister
if cfg.EnablePprof || cfg.Debug {
sctx.registerPprof()
}
if cfg.Debug {
sctx.registerTrace()
}
sctxs[addr] = sctx //记录当前serverCtx实例
}
```
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: dc8016287344ee6ece572a1c3f1fdf6a6525ce9d
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.