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

mozilla/mig: mig-scheduler/scheduler.go; 31 LoC

Open
#13,737 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 [mozilla/mig](https://www.github.com/mozilla/mig) at [mig-scheduler/scheduler.go](https://github.com/mozilla/mig/blob/9e7e4f5258051e9edc94e407821f693e9d8c85ea/mig-scheduler/scheduler.go#L209-L239)

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 cmd used in defer or goroutine at line 233

[Click here to see the code in its original context.](https://github.com/mozilla/mig/blob/9e7e4f5258051e9edc94e407821f693e9d8c85ea/mig-scheduler/scheduler.go#L209-L239)

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

```go
for _, cmd := range cmds {
data, err := json.Marshal(cmd)
if err != nil {
panic(err)
}
// write command to InFlight directory
dest := fmt.Sprintf("%s/%.0f-%.0f.json", ctx.Directories.Command.InFlight, cmd.Action.ID, cmd.ID)
err = safeWrite(ctx, dest, data)
if err != nil {
panic(err)
}
// send amqp message with an expiration timer
expire := cmd.Action.ExpireAfter.Sub(cmd.Action.ValidFrom)
msg := amqp.Publishing{
DeliveryMode: amqp.Persistent,
Timestamp: time.Now(),
ContentType: "text/plain",
Expiration: fmt.Sprintf("%d", int64(expire/time.Millisecond)),
Body: []byte(data),
}
agtQueue := fmt.Sprintf("mig.agt.%s", cmd.Agent.QueueLoc)
go func() {
err = ctx.MQ.Chan.Publish(mig.ExchangeToAgents, agtQueue, true, false, msg)
if err != nil {
ctx.Channels.Log <- mig.Log{OpID: ctx.OpID, ActionID: cmd.Action.ID, CommandID: cmd.ID, Desc: "publishing failed to queue" + agtQueue}.Err()
} else {
desc := fmt.Sprintf("published to queue %s", agtQueue)
ctx.Channels.Log <- mig.Log{OpID: ctx.OpID, ActionID: cmd.Action.ID, CommandID: cmd.ID, Desc: desc}
}
}()
}

```

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: 9e7e4f5258051e9edc94e407821f693e9d8c85ea

Contributor guide

No contributing guide indexed for this repository

Research direction

Read mig-scheduler/scheduler.go at lines 209-239, starting with the range over cmds and the goroutine that publishes the AMQP message. Verify how the goroutine uses cmd, msg, agtQueue, and err across iterations; done means each publication and log entry corresponds to its intended command without range-loop capture or shared-state errors.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.