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

bobvawter/iaido: pkg/frontend/frontend.go; 70 LoC

Open
#17,057 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 [bobvawter/iaido](https://www.github.com/bobvawter/iaido) at [pkg/frontend/frontend.go](https://github.com/bobvawter/iaido/blob/ca314ef9741d90f948a5f3c40ac2dfe56c9f2b56/pkg/frontend/frontend.go#L77-L146)

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 fe used in defer or goroutine at line 105

[Click here to see the code in its original context.](https://github.com/bobvawter/iaido/blob/ca314ef9741d90f948a5f3c40ac2dfe56c9f2b56/pkg/frontend/frontend.go#L77-L146)

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

```go
for _, fe := range cfg.Frontends {
tgt, err := config.ParseTarget(fe.BindAddress)
if err != nil {
return errors.Wrapf(err, "could not bind %q", fe.BindAddress)
}
activeTargets[tgt.String()] = true

bl := f.mu.loops[tgt.String()]
if bl == nil {
loopCtx, cancel := context.WithCancel(ctx)
bl = &balanceLoop{
balancer: &balancer.Balancer{},
cancel: cancel,
}

if err := bl.balancer.Configure(loopCtx, fe.BackendPool, true); err != nil {
return errors.Wrapf(err, "could not configure backend pool for %q", fe.BindAddress)
}

// Establish initial latency values.
bl.balancer.Rebalance(loopCtx)

f.mu.loops[tgt.String()] = bl

// Set up a loop to rebalance the pool (e.g. to reactivate
// disabled backends or prune overloaded nodes.)
if fe.RebalanceDuration > 0 {
go func(b *balancer.Balancer) {
ticker := time.NewTicker(fe.RebalanceDuration)
defer ticker.Stop()
for {
select {
case <-loopCtx.Done():
return
case <-ticker.C:
b.Rebalance(loopCtx)
}
}
}(bl.balancer)
}

switch tgt.Proto {
case config.TCP:
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
IP: net.ParseIP(tgt.Hosts[0]),
Port: tgt.Port,
})
if err != nil {
return errors.Wrapf(err, "could not bind %q", tgt)
}
log.Printf("listening on %s", listener.Addr())
bl.listener = listener

loop.New(
// Don't Accept() a connection until a backend can be chosen.
loop.WithPreflight(func(ctx context.Context) (context.Context, error) {
token, err := bl.balancer.Wait(ctx)
return context.WithValue(ctx, balancer.KeyBackendToken, token), err
}),
tcp.Proxy(listener, fe.IdleDuration),
loop.WithLatch(f.mu.latch),
).Start(loopCtx)
default:
panic(errors.Errorf("unimplemented: %s", tgt.Proto))
}
} else if err := bl.balancer.Configure(ctx, fe.BackendPool, true); err != nil {
return errors.Wrapf(err, "could not configure backend pool for %q", fe.BindAddress)
}

}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with pkg/frontend/frontend.go lines 77-146 and inspect the reported range-loop capture around line 105, including the goroutine and deferred ticker cleanup. Decide whether the analyzer finding is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction on issue #17057.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.