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

pulcy/helix: service/service.go; 50 LoC

Open
#15,704 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 [pulcy/helix](https://www.github.com/pulcy/helix) at [service/service.go](https://github.com/pulcy/helix/blob/23d919222e1dd8654039ad6364c91a93ab956c38/service/service.go#L322-L371)

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 s used in defer or goroutine at line 352

[Click here to see the code in its original context.](https://github.com/pulcy/helix/blob/23d919222e1dd8654039ad6364c91a93ab956c38/service/service.go#L322-L371)

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

```go
for _, s := range services {
if sNode, ok := s.(ServiceNodeInitializer); ok {
wg := sync.WaitGroup{}
errors := make(chan error, len(clients))
defer close(errors)
for i, client := range clients {
wg.Add(1)
go func(client util.SSHClient, node *Node) {
defer wg.Done()
if err := sNode.InitNode(node, client, sctx, deps, flags); err != nil {
errors <- maskAny(err)
}
}(client, nodes[i])
}
wg.Wait()
select {
case err := <-errors:
return maskAny(err)
default:
// Continue
}
}
if sMachine, ok := s.(ServiceMachines); ok {
wg := sync.WaitGroup{}
errors := make(chan error, len(clients))
defer close(errors)
for i, client := range clients {
wg.Add(1)
go func(client util.SSHClient, node Node) {
defer wg.Done()
deps.Logger.Info().Msgf("Resetting %s service on %s", s.Name(), node.Name)
if err := sMachine.ResetMachine(node, client, sctx, deps, flags); err != nil {
errors <- maskAny(err)
}
}(client, *nodes[i])
}
wg.Wait()
select {
case err := <-errors:
return maskAny(err)
default:
// Continue
}
}
if reseter, ok := s.(ServiceReseter); ok {
if err := reseter.Reset(sctx, deps, flags); err != nil {
return maskAny(err)
}
}
}

```

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: 23d919222e1dd8654039ad6364c91a93ab956c38

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with service/service.go lines 322-371 and inspect the range over services, the goroutines, and deferred cleanup. Then review the linked analyzer context and the project guidance for the Bug, Mitigated, or Desirable Behavior reactions; done means leaving the appropriate classification reaction.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.