github-vet / github-vet/rangeloop-pointer-findings
blackstar138/auto-patient-zero: mig-scheduler/scheduler.go; 31 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [blackstar138/auto-patient-zero](https://www.github.com/blackstar138/auto-patient-zero) at [mig-scheduler/scheduler.go](https://github.com/blackstar138/auto-patient-zero/blob/54f72e2f7adfb75b1b2cdf9ffda616d935b68a3c/mig-scheduler/scheduler.go#L203-L233)
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 227
[Click here to see the code in its original context.](https://github.com/blackstar138/auto-patient-zero/blob/54f72e2f7adfb75b1b2cdf9ffda616d935b68a3c/mig-scheduler/scheduler.go#L203-L233)
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.Mq_Ex_ToAgents, 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: 54f72e2f7adfb75b1b2cdf9ffda616d935b68a3c
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.