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

alienvspredator/IRC-client: internal/app/telegram/updates.go; 86 LoC

Open
#7,948 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 [alienvspredator/IRC-client](https://www.github.com/alienvspredator/IRC-client) at [internal/app/telegram/updates.go](https://github.com/alienvspredator/IRC-client/blob/0569e7d8f9a7f9d09963f94a33d3c2cc966b744e/internal/app/telegram/updates.go#L20-L105)

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 update used in defer or goroutine at line 77

[Click here to see the code in its original context.](https://github.com/alienvspredator/IRC-client/blob/0569e7d8f9a7f9d09963f94a33d3c2cc966b744e/internal/app/telegram/updates.go#L20-L105)

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

```go
for update := range ch {
// Listen only message updates
if update.Message == nil {
continue
}

if cmd := update.Message.Command(); cmd != "" {
if cmd != "connect" {
continue
}

cfg := ircparser.ParseConnectString(update.Message.CommandArguments())
conn, err := net.Dial("tcp", cfg.Host)
if err != nil {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
fmt.Sprintf("Cannot connect to the given host: %v", err),
))
}

ctx := context.TODO()
client := ircwrapper.NewWrapper(ctx, conn, cfg.WrapperConfig)

u := tgbotapi.NewUpdate(0)
u.Timeout = 60

fUpdates, err := tgupdates.GetFilteredUpdatesChan(
a.botAPI,
tgupdates.FilteredUpdateConfig{
UpdateConfig: u,
ChatID: update.Message.Chat.ID,
},
)
if err != nil {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
fmt.Sprintf("Cannot get updates channel: %v", err),
))
}

ircUpdChan, err := client.GetUpdatesChan()
if err != nil {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
fmt.Sprintf("Cannot get IRC updates channel: %v", err),
))
}

inputer := tginput.NewInput(
ctx,
fUpdates,
)

inputch := inputer.NewInputChan()
go func() {
for upd := range ircUpdChan {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
upd.Message.String(),
))
}
}()

go func() {
for in := range inputch {
if err := in.Error; err != nil {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
fmt.Sprintf("Got update error: %v", err),
))

continue
}

if err := client.WriteMessage(in.Message); err != nil {
a.botAPI.Send(tgbotapi.NewMessage(
update.Message.Chat.ID,
fmt.Sprintf("Cannot send message: %v", err),
))
}
}
}()
}

a.logger.Info("Got new message", zap.String("Message", update.Message.Text))
}

```

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: 0569e7d8f9a7f9d09963f94a33d3c2cc966b744e

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.