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

hiyunan/etcd: etcdmain/etcd.go; 61 LoC

Open
#13,999 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 [hiyunan/etcd](https://www.github.com/hiyunan/etcd) at [etcdmain/etcd.go](https://github.com/hiyunan/etcd/blob/b0cc0e443c163f36f29d078dd855ca9c7b68e612/etcdmain/etcd.go#L269-L329)

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 325

[Click here to see the code in its original context.](https://github.com/hiyunan/etcd/blob/b0cc0e443c163f36f29d078dd855ca9c7b68e612/etcdmain/etcd.go#L269-L329)

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

```go
for _, u := range cfg.lcurls {
if u.Scheme == "http" {
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" && ctlscfg == nil {
return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String())
}

ctx := &serveCtx{host: u.Host}

if u.Scheme == "https" {
ctx.secure = true
} else {
ctx.insecure = true
}

if sctxs[u.Host] != nil {
if ctx.secure {
sctxs[u.Host].secure = true
}
if ctx.insecure {
sctxs[u.Host].insecure = true
}
continue
}

var l net.Listener

l, err = net.Listen("tcp", u.Host)
if err != nil {
return nil, err
}

var fdLimit uint64
if fdLimit, err = runtimeutil.FDLimit(); err == 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)
}
l = transport.LimitListener(l, int(fdLimit-reservedInternalFDNum))
}

l, err = transport.NewKeepAliveListener(l, "tcp", nil)
ctx.l = l
if err != nil {
return nil, err
}

plog.Info("listening for client requests on ", u.Host)
defer func() {
if err != nil {
l.Close()
plog.Info("stopping listening for client requests on ", u.Host)
}
}()
sctxs[u.Host] = ctx
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Read etcdmain/etcd.go lines 269-329 and inspect the deferred closure inside the cfg.lcurls loop. Check how the loop variable u is captured under the relevant Go version, then classify the finding as Bug, Mitigated, or Desirable Behavior using the project’s classification guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.