From d5dbe546e461261056b5fda1a2ac9fc6d36c69e1 Mon Sep 17 00:00:00 2001 From: Kiril Vladimiroff Date: Tue, 11 Feb 2020 16:12:21 +0200 Subject: Always defer *sql.Rows.Close and consult with Err (#844) * Always defer *sql.Rows.Close and consult with Err database/sql.Rows.Next() makes sure to call Close only after exhausting result rows which would NOT happen when returning early from a bad Scan. Close being idempotent makes it a great candidate to get always deferred regardless of what happens later on the result set. This change also makes sure call Err() after exhausting Next() and propagate non-nil results from it as the documentation advises. Closes #764 Signed-off-by: Kiril Vladimiroff * Override named result parameters in last returns Signed-off-by: Kiril Vladimiroff * Do the same over new changes that got merged Signed-off-by: Kiril Vladimiroff Co-authored-by: Neil Alexander --- syncapi/storage/postgres/backward_extremities_table.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'syncapi/storage/postgres/backward_extremities_table.go') diff --git a/syncapi/storage/postgres/backward_extremities_table.go b/syncapi/storage/postgres/backward_extremities_table.go index 1489f7f9..d63c546e 100644 --- a/syncapi/storage/postgres/backward_extremities_table.go +++ b/syncapi/storage/postgres/backward_extremities_table.go @@ -91,6 +91,7 @@ func (s *backwardExtremitiesStatements) selectBackwardExtremitiesForRoom( if err != nil { return } + defer rows.Close() // nolint: errcheck for rows.Next() { var eID string @@ -101,7 +102,7 @@ func (s *backwardExtremitiesStatements) selectBackwardExtremitiesForRoom( eventIDs = append(eventIDs, eID) } - return + return eventIDs, rows.Err() } func (s *backwardExtremitiesStatements) isBackwardExtremity( -- cgit v1.2.3