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

pganalyze/collector: logs/stream/stream.go; 27 LoC

Open
#13,387 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 [pganalyze/collector](https://www.github.com/pganalyze/collector) at [logs/stream/stream.go](https://github.com/pganalyze/collector/blob/e04b0419bedaf9a2f09d0752ca6f6df75eeca6fc/logs/stream/stream.go#L51-L77)

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.

> reference to logLine is reassigned at line 71

[Click here to see the code in its original context.](https://github.com/pganalyze/collector/blob/e04b0419bedaf9a2f09d0752ca6f6df75eeca6fc/logs/stream/stream.go#L51-L77)

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

```go
for _, logLine := range logLines {
if logLine.LogLevel == pganalyze_collector.LogLineInformation_UNKNOWN {
if logLine.BackendPid != 0 {
// Heroku case (Unknown log lines have PIDs assigned)
if lastPrimaryLogLine != nil && logLine.BackendPid == lastPrimaryLogLine.BackendPid {
readyLogLines = append(readyLogLines, logLine)
} else {
tooFreshLogLines = append(tooFreshLogLines, logLine)
}
} else {
if lastPrimaryLogLine != nil {
// Self-managed and Google Cloud SQL case - we always stitch unknown log levels to the prior line
readyLogLines = append(readyLogLines, logLine)
} else if now.Sub(logLine.CollectedAt) <= threshold {
tooFreshLogLines = append(tooFreshLogLines, logLine)
}
}
} else {
if now.Sub(logLine.CollectedAt) > threshold {
readyLogLines = append(readyLogLines, logLine)
lastPrimaryLogLine = &logLine
} else {
tooFreshLogLines = append(tooFreshLogLines, logLine)
lastPrimaryLogLine = nil
}
}
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Read logs/stream/stream.go lines 51-77 at commit e04b0419 and review how the range variable logLine is referenced after assignment. Check whether the analyzer finding represents a real bug, a mitigated case, or desirable behavior, then leave the corresponding reaction on this issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.