handleIncidentTimeline: check rows.Err() after the Next() loop #27

Closed
opened 2026-10-03 07:02:00 +00:00 by niklas · 2 comments
Owner

handleIncidentTimeline in internal/api/incidents.go loops over rows.Next() to scan timeline events but never checks rows.Err() after the loop, so a connection error or cancellation partway through the scan would silently return a truncated timeline as if it were complete, rather than a 500.

Flagged by the sqlrowserr lint check while working on #26 (unrelated to that issue's scope, so left alone there and filed separately here).

Fix: after the for rows.Next() { ... } loop, add

if err := rows.Err(); err != nil {
    respond(w, http.StatusInternalServerError, errResp("internal error"))
    return
}

matching the pattern other handlers in this package already use after their own rows.Next() loops.

`handleIncidentTimeline` in `internal/api/incidents.go` loops over `rows.Next()` to scan timeline events but never checks `rows.Err()` after the loop, so a connection error or cancellation partway through the scan would silently return a truncated timeline as if it were complete, rather than a 500. Flagged by the `sqlrowserr` lint check while working on #26 (unrelated to that issue's scope, so left alone there and filed separately here). Fix: after the `for rows.Next() { ... }` loop, add ```go if err := rows.Err(); err != nil { respond(w, http.StatusInternalServerError, errResp("internal error")) return } ``` matching the pattern other handlers in this package already use after their own `rows.Next()` loops.
Author
Owner

Fixed on main.

  • dc62278: handleIncidentTimeline checks rows.Err() after the scan loop and returns a 500.
  • 3613fd5: the same check added to the other loops that lacked it: the incident list (handleListIncidents), the three stats breakdowns in stats.go, and the user list in users.go. sqlrowserr no longer flags anything, and make fmt lint test helm-lint is green.

No new tests: a mid-scan failure can't be triggered against the real Postgres the suite uses.

Fixed on `main`. - `dc62278`: `handleIncidentTimeline` checks `rows.Err()` after the scan loop and returns a 500. - `3613fd5`: the same check added to the other loops that lacked it: the incident list (`handleListIncidents`), the three stats breakdowns in `stats.go`, and the user list in `users.go`. `sqlrowserr` no longer flags anything, and `make fmt lint test helm-lint` is green. No new tests: a mid-scan failure can't be triggered against the real Postgres the suite uses.
Author
Owner

Shipped in v0.39.0 (image published, trivy scan clean). Deploy is pending the wrapper-chart PR: Ryuvia/charts#299. Closing.

Shipped in v0.39.0 (image published, trivy scan clean). Deploy is pending the wrapper-chart PR: https://git.ryuvia.com/Ryuvia/charts/pulls/299. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: niklas/terdut-server#27