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

zhuanxuhit/distributed-system: etcd-raft/vendor/github.com/coreos/etcd/embed/etcd.go; 55 LoC

Open
#10,622 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [zhuanxuhit/distributed-system](https://www.github.com/zhuanxuhit/distributed-system) at [etcd-raft/vendor/github.com/coreos/etcd/embed/etcd.go](https://github.com/zhuanxuhit/distributed-system/blob/d4bd34f3c8aee67d949d471a8ac9382e5820c05c/etcd-raft/vendor/github.com/coreos/etcd/embed/etcd.go#L234-L288)

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 283

[Click here to see the code in its original context.](https://github.com/zhuanxuhit/distributed-system/blob/d4bd34f3c8aee67d949d471a8ac9382e5820c05c/etcd-raft/vendor/github.com/coreos/etcd/embed/etcd.go#L234-L288)

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

```go
for _, u := range cfg.LCUrls {
sctx := newServeCtx()

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"
if u.Scheme == "unix" || u.Scheme == "unixs" {
proto = "unix"
}

sctx.secure = u.Scheme == "https" || u.Scheme == "unixs"
sctx.insecure = !sctx.secure
if oldctx := sctxs[u.Host]; oldctx != nil {
oldctx.secure = oldctx.secure || sctx.secure
oldctx.insecure = oldctx.insecure || sctx.insecure
continue
}

if sctx.l, err = net.Listen(proto, u.Host); err != nil {
return nil, err
}

if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil {
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)
}
}()
sctx.userHandlers = cfg.UserHandlers
sctxs[u.Host] = sctx
}

```

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: d4bd34f3c8aee67d949d471a8ac9382e5820c05c

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.