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

timrourke/funnel: upload/upload.go; 46 LoC

Open
#7,380 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 [timrourke/funnel](https://www.github.com/timrourke/funnel) at [upload/upload.go](https://github.com/timrourke/funnel/blob/e5dfa8b943a5022a5d60aeb20550a6a79b5fa6e6/upload/upload.go#L133-L178)

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 input used in defer or goroutine at line 173

[Click here to see the code in its original context.](https://github.com/timrourke/funnel/blob/e5dfa8b943a5022a5d60aeb20550a6a79b5fa6e6/upload/upload.go#L133-L178)

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

```go
for input := range pending {
key, err := u.keyTemplate.KeyForFile(input.path)
if err != nil {
u.logger.WithFields(logrus.Fields{
"filename": input.path,
"error": err,
}).Errorf("Failed to parse template for S3 object key: %w", err)
}

err = u.s3Uploader.Upload(input.path, key)
if err == nil && u.shouldDeleteFileAfterUpload {
err = os.Remove(input.path)
if err != nil && errors.Is(err, os.ErrNotExist) {
u.logger.WithFields(logrus.Fields{
"filename": input.path,
"error": err.Error(),
}).Warnf(
"Attempted to delete a file that no longer exists, did something else already delete it?: %s: %w",
input.path,
err,
)
completed <- input
continue
}
if err != nil {
u.logger.WithFields(logrus.Fields{
"filename": input.path,
"error": err.Error(),
}).Fatal(fmt.Sprintf("Failed to delete file after upload: %s", input.path))
}
}
if err == nil {
completed <- input
continue
}

input.errors = append(input.errors, err)

if len(input.errors) < 5 {
go func() {
pending <- input
}()
} else {
failed <- input
}
}

```

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

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.