Log errors from rows.Close (#920)

* Log errors from rows.Close

* fixed imports

* Added contextual messages

* fixed review changes
main
Prateek Sachan 2020-03-18 15:47:18 +05:30 committed by GitHub
parent c2bd0b97b3
commit c019ad7086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 118 additions and 69 deletions

View File

@ -18,6 +18,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -90,7 +92,7 @@ func (s *accountDataStatements) selectAccountData(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectAccountData: rows.close() failed")
global = []gomatrixserverlib.ClientEvent{} global = []gomatrixserverlib.ClientEvent{}
rooms = make(map[string][]gomatrixserverlib.ClientEvent) rooms = make(map[string][]gomatrixserverlib.ClientEvent)

View File

@ -18,6 +18,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/authtypes"
) )
@ -118,7 +120,7 @@ func (s *membershipStatements) selectMembershipsByLocalpart(
memberships = []authtypes.Membership{} memberships = []authtypes.Membership{}
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed")
for rows.Next() { for rows.Next() {
var m authtypes.Membership var m authtypes.Membership
m.Localpart = localpart m.Localpart = localpart

View File

@ -118,7 +118,7 @@ func (s *membershipStatements) selectMembershipsByLocalpart(
memberships = []authtypes.Membership{} memberships = []authtypes.Membership{}
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsByLocalpart: rows.close() failed")
for rows.Next() { for rows.Next() {
var m authtypes.Membership var m authtypes.Membership
m.Localpart = localpart m.Localpart = localpart

View File

@ -97,7 +97,7 @@ func (s *threepidStatements) selectThreePIDsForLocalpart(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectThreePIDsForLocalpart: rows.close() failed")
threepids = []authtypes.ThreePID{} threepids = []authtypes.ThreePID{}
for rows.Next() { for rows.Next() {

View File

@ -226,7 +226,7 @@ func (s *devicesStatements) selectDevicesByLocalpart(
if err != nil { if err != nil {
return devices, err return devices, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectDevicesByLocalpart: rows.close() failed")
for rows.Next() { for rows.Next() {
var dev authtypes.Device var dev authtypes.Device

View File

@ -19,6 +19,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -91,7 +93,7 @@ func (s *serverKeyStatements) bulkSelectServerKeys(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed")
results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{} results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{}
for rows.Next() { for rows.Next() {
var serverName string var serverName string

View File

@ -124,7 +124,7 @@ func (s *serverKeyStatements) bulkSelectServerKeys(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectServerKeys: rows.close() failed")
results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{} results := map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult{}
for rows.Next() { for rows.Next() {
var serverName string var serverName string

View File

@ -15,13 +15,17 @@
package common package common
import ( import (
"context"
"fmt" "fmt"
"io"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
"github.com/matrix-org/dugong" "github.com/matrix-org/dugong"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -156,3 +160,17 @@ func setupFileHook(hook config.LogrusHook, level logrus.Level, componentName str
), ),
}) })
} }
//CloseAndLogIfError Closes io.Closer and logs the error if any
func CloseAndLogIfError(ctx context.Context, closer io.Closer, message string) {
if closer == nil {
return
}
err := closer.Close()
if ctx == nil {
ctx = context.TODO()
}
if err != nil {
util.GetLogger(ctx).WithError(err).Error(message)
}
}

View File

@ -90,7 +90,7 @@ func (s *PartitionOffsetStatements) selectPartitionOffsets(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer CloseAndLogIfError(ctx, rows, "selectPartitionOffsets: rows.close() failed")
var results []PartitionOffset var results []PartitionOffset
for rows.Next() { for rows.Next() {
var offset PartitionOffset var offset PartitionOffset

View File

@ -118,7 +118,7 @@ func joinedHostsFromStmt(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed")
var result []types.JoinedHost var result []types.JoinedHost
for rows.Next() { for rows.Next() {

View File

@ -121,7 +121,7 @@ func joinedHostsFromStmt(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "joinedHostsFromStmt: rows.close() failed")
var result []types.JoinedHost var result []types.JoinedHost
for rows.Next() { for rows.Next() {

3
go.mod
View File

@ -15,10 +15,13 @@ require (
github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7
github.com/mattn/go-sqlite3 v2.0.2+incompatible github.com/mattn/go-sqlite3 v2.0.2+incompatible
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5
github.com/opentracing/opentracing-go v1.1.0 github.com/opentracing/opentracing-go v1.1.0
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.4.1 github.com/prometheus/client_golang v1.4.1
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/sirupsen/logrus v1.4.2 github.com/sirupsen/logrus v1.4.2
github.com/tidwall/gjson v1.6.0 // indirect github.com/tidwall/gjson v1.6.0 // indirect
github.com/tidwall/pretty v1.0.1 // indirect github.com/tidwall/pretty v1.0.1 // indirect

2
go.sum
View File

@ -372,6 +372,8 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ= github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=

View File

@ -20,6 +20,8 @@ import (
"database/sql" "database/sql"
"time" "time"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/dendrite/mediaapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -144,7 +146,7 @@ func (s *thumbnailStatements) selectThumbnails(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed")
var thumbnails []*types.ThumbnailMetadata var thumbnails []*types.ThumbnailMetadata
for rows.Next() { for rows.Next() {

View File

@ -20,6 +20,8 @@ import (
"database/sql" "database/sql"
"time" "time"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/mediaapi/types" "github.com/matrix-org/dendrite/mediaapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -134,7 +136,7 @@ func (s *thumbnailStatements) selectThumbnails(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectThumbnails: rows.close() failed")
var thumbnails []*types.ThumbnailMetadata var thumbnails []*types.ThumbnailMetadata
for rows.Next() { for rows.Next() {

View File

@ -21,6 +21,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/matrix-org/dendrite/common"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/publicroomsapi/types" "github.com/matrix-org/dendrite/publicroomsapi/types"
) )
@ -203,7 +205,7 @@ func (s *publicRoomsStatements) selectPublicRooms(
if err != nil { if err != nil {
return []types.PublicRoom{}, nil return []types.PublicRoom{}, nil
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectPublicRooms: rows.close() failed")
rooms := []types.PublicRoom{} rooms := []types.PublicRoom{}
for rows.Next() { for rows.Next() {

View File

@ -19,6 +19,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
) )
@ -86,7 +88,7 @@ func (s *eventJSONStatements) bulkSelectEventJSON(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed")
// We know that we will only get as many results as event NIDs // We know that we will only get as many results as event NIDs
// because of the unique constraint on event NIDs. // because of the unique constraint on event NIDs.

View File

@ -114,7 +114,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed")
result := make(map[string]types.EventStateKeyNID, len(eventStateKeys)) result := make(map[string]types.EventStateKeyNID, len(eventStateKeys))
for rows.Next() { for rows.Next() {
@ -139,7 +139,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed")
result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs)) result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs))
for rows.Next() { for rows.Next() {

View File

@ -19,6 +19,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
) )
@ -132,7 +134,7 @@ func (s *eventTypeStatements) bulkSelectEventTypeNID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed")
result := make(map[string]types.EventTypeNID, len(eventTypes)) result := make(map[string]types.EventTypeNID, len(eventTypes))
for rows.Next() { for rows.Next() {

View File

@ -192,7 +192,7 @@ func (s *eventStatements) bulkSelectStateEventByID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed")
// We know that we will only get as many results as event IDs // We know that we will only get as many results as event IDs
// because of the unique constraint on event IDs. // because of the unique constraint on event IDs.
// So we can allocate an array of the correct size now. // So we can allocate an array of the correct size now.
@ -235,7 +235,7 @@ func (s *eventStatements) bulkSelectStateAtEventByID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed")
results := make([]types.StateAtEvent, len(eventIDs)) results := make([]types.StateAtEvent, len(eventIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -302,7 +302,7 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed")
results := make([]types.StateAtEventAndReference, len(eventNIDs)) results := make([]types.StateAtEventAndReference, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -343,7 +343,7 @@ func (s *eventStatements) bulkSelectEventReference(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed")
results := make([]gomatrixserverlib.EventReference, len(eventNIDs)) results := make([]gomatrixserverlib.EventReference, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -367,7 +367,7 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, eventNIDs []typ
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed")
results := make(map[types.EventNID]string, len(eventNIDs)) results := make(map[types.EventNID]string, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -394,7 +394,7 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, eventIDs []str
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed")
results := make(map[string]types.EventNID, len(eventIDs)) results := make(map[string]types.EventNID, len(eventIDs))
for rows.Next() { for rows.Next() {
var eventID string var eventID string

View File

@ -120,7 +120,7 @@ func (s *inviteStatements) updateInviteRetired(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "updateInviteRetired: rows.close() failed")
var eventIDs []string var eventIDs []string
for rows.Next() { for rows.Next() {
@ -144,7 +144,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed")
var result []types.EventStateKeyNID var result []types.EventStateKeyNID
for rows.Next() { for rows.Next() {
var senderUserNID int64 var senderUserNID int64

View File

@ -151,7 +151,7 @@ func (s *membershipStatements) selectMembershipsFromRoom(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed")
for rows.Next() { for rows.Next() {
var eNID types.EventNID var eNID types.EventNID
@ -172,7 +172,7 @@ func (s *membershipStatements) selectMembershipsFromRoomAndMembership(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed")
for rows.Next() { for rows.Next() {
var eNID types.EventNID var eNID types.EventNID

View File

@ -18,6 +18,8 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
) )
const roomAliasesSchema = ` const roomAliasesSchema = `
@ -95,7 +97,7 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed")
var aliases []string var aliases []string
for rows.Next() { for rows.Next() {

View File

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
"sort" "sort"
"github.com/matrix-org/dendrite/common"
"github.com/lib/pq" "github.com/lib/pq"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/util" "github.com/matrix-org/util"
@ -138,7 +140,7 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed")
results := make([]types.StateEntryList, len(stateBlockNIDs)) results := make([]types.StateEntryList, len(stateBlockNIDs))
// current is a pointer to the StateEntryList to append the state entries to. // current is a pointer to the StateEntryList to append the state entries to.
@ -197,7 +199,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed")
var results []types.StateEntryList var results []types.StateEntryList
var current types.StateEntryList var current types.StateEntryList

View File

@ -88,7 +88,7 @@ func (s *eventJSONStatements) bulkSelectEventJSON(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventJSON: rows.close() failed")
// We know that we will only get as many results as event NIDs // We know that we will only get as many results as event NIDs
// because of the unique constraint on event NIDs. // because of the unique constraint on event NIDs.

View File

@ -116,7 +116,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKeyNID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKeyNID: rows.close() failed")
result := make(map[string]types.EventStateKeyNID, len(eventStateKeys)) result := make(map[string]types.EventStateKeyNID, len(eventStateKeys))
for rows.Next() { for rows.Next() {
var stateKey string var stateKey string
@ -142,7 +142,7 @@ func (s *eventStateKeyStatements) bulkSelectEventStateKey(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventStateKey: rows.close() failed")
result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs)) result := make(map[types.EventStateKeyNID]string, len(eventStateKeyNIDs))
for rows.Next() { for rows.Next() {
var stateKey string var stateKey string

View File

@ -138,7 +138,7 @@ func (s *eventTypeStatements) bulkSelectEventTypeNID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventTypeNID: rows.close() failed")
result := make(map[string]types.EventTypeNID, len(eventTypes)) result := make(map[string]types.EventTypeNID, len(eventTypes))
for rows.Next() { for rows.Next() {

View File

@ -194,7 +194,7 @@ func (s *eventStatements) bulkSelectStateEventByID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateEventByID: rows.close() failed")
// We know that we will only get as many results as event IDs // We know that we will only get as many results as event IDs
// because of the unique constraint on event IDs. // because of the unique constraint on event IDs.
// So we can allocate an array of the correct size now. // So we can allocate an array of the correct size now.
@ -247,7 +247,7 @@ func (s *eventStatements) bulkSelectStateAtEventByID(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventByID: rows.close() failed")
results := make([]types.StateAtEvent, len(eventIDs)) results := make([]types.StateAtEvent, len(eventIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -323,7 +323,7 @@ func (s *eventStatements) bulkSelectStateAtEventAndReference(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateAtEventAndReference: rows.close() failed")
results := make([]types.StateAtEventAndReference, len(eventNIDs)) results := make([]types.StateAtEventAndReference, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -374,7 +374,7 @@ func (s *eventStatements) bulkSelectEventReference(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventReference: rows.close() failed")
results := make([]gomatrixserverlib.EventReference, len(eventNIDs)) results := make([]gomatrixserverlib.EventReference, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -408,7 +408,7 @@ func (s *eventStatements) bulkSelectEventID(ctx context.Context, txn *sql.Tx, ev
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventID: rows.close() failed")
results := make(map[types.EventNID]string, len(eventNIDs)) results := make(map[types.EventNID]string, len(eventNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {
@ -445,7 +445,7 @@ func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, e
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectEventNID: rows.close() failed")
results := make(map[string]types.EventNID, len(eventIDs)) results := make(map[string]types.EventNID, len(eventIDs))
for rows.Next() { for rows.Next() {
var eventID string var eventID string

View File

@ -137,7 +137,7 @@ func (s *inviteStatements) selectInviteActiveForUserInRoom(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectInviteActiveForUserInRoom: rows.close() failed")
var result []types.EventStateKeyNID var result []types.EventStateKeyNID
for rows.Next() { for rows.Next() {
var senderUserNID int64 var senderUserNID int64

View File

@ -134,7 +134,7 @@ func (s *membershipStatements) selectMembershipsFromRoom(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoom: rows.close() failed")
for rows.Next() { for rows.Next() {
var eNID types.EventNID var eNID types.EventNID
@ -154,7 +154,7 @@ func (s *membershipStatements) selectMembershipsFromRoomAndMembership(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectMembershipsFromRoomAndMembership: rows.close() failed")
for rows.Next() { for rows.Next() {
var eNID types.EventNID var eNID types.EventNID

View File

@ -103,7 +103,7 @@ func (s *roomAliasesStatements) selectAliasesFromRoomID(
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectAliasesFromRoomID: rows.close() failed")
for rows.Next() { for rows.Next() {
var alias string var alias string

View File

@ -137,7 +137,7 @@ func (s *stateBlockStatements) bulkSelectStateBlockEntries(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockEntries: rows.close() failed")
results := make([]types.StateEntryList, len(stateBlockNIDs)) results := make([]types.StateEntryList, len(stateBlockNIDs))
// current is a pointer to the StateEntryList to append the state entries to. // current is a pointer to the StateEntryList to append the state entries to.
@ -207,7 +207,7 @@ func (s *stateBlockStatements) bulkSelectFilteredStateBlockEntries(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectFilteredStateBlockEntries: rows.close() failed")
var results []types.StateEntryList var results []types.StateEntryList
var current types.StateEntryList var current types.StateEntryList

View File

@ -99,7 +99,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "bulkSelectStateBlockNIDs: rows.close() failed")
results := make([]types.StateBlockNIDList, len(stateNIDs)) results := make([]types.StateBlockNIDList, len(stateNIDs))
i := 0 i := 0
for ; rows.Next(); i++ { for ; rows.Next(); i++ {

View File

@ -118,7 +118,7 @@ func (s *accountDataStatements) selectAccountDataInRange(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed")
for rows.Next() { for rows.Next() {
var dataType string var dataType string

View File

@ -17,6 +17,8 @@ package postgres
import ( import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
) )
const backwardExtremitiesSchema = ` const backwardExtremitiesSchema = `
@ -91,7 +93,7 @@ func (s *backwardExtremitiesStatements) selectBackwardExtremitiesForRoom(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectBackwardExtremitiesForRoom: rows.close() failed")
for rows.Next() { for rows.Next() {
var eID string var eID string

View File

@ -140,7 +140,7 @@ func (s *currentRoomStateStatements) selectJoinedUsers(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed")
result := make(map[string][]string) result := make(map[string][]string)
for rows.Next() { for rows.Next() {
@ -168,7 +168,7 @@ func (s *currentRoomStateStatements) selectRoomIDsWithMembership(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed")
var result []string var result []string
for rows.Next() { for rows.Next() {
@ -198,7 +198,7 @@ func (s *currentRoomStateStatements) selectCurrentState(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed")
return rowsToEvents(rows) return rowsToEvents(rows)
} }
@ -248,7 +248,7 @@ func (s *currentRoomStateStatements) selectEventsWithEventIDs(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed")
return rowsToStreamEvents(rows) return rowsToStreamEvents(rows)
} }

View File

@ -115,7 +115,7 @@ func (s *inviteEventsStatements) selectInviteEventsInRange(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
result := map[string]gomatrixserverlib.Event{} result := map[string]gomatrixserverlib.Event{}
for rows.Next() { for rows.Next() {
var ( var (

View File

@ -169,7 +169,7 @@ func (s *outputRoomEventsStatements) selectStateInRange(
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectStateInRange: rows.close() failed")
// Fetch all the state change events for all rooms between the two positions then loop each event and: // Fetch all the state change events for all rooms between the two positions then loop each event and:
// - Keep a cache of the event by ID (99% of state change events are for the event itself) // - Keep a cache of the event by ID (99% of state change events are for the event itself)
// - For each room ID, build up an array of event IDs which represents cumulative adds/removes // - For each room ID, build up an array of event IDs which represents cumulative adds/removes
@ -303,7 +303,7 @@ func (s *outputRoomEventsStatements) selectRecentEvents(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed")
events, err := rowsToStreamEvents(rows) events, err := rowsToStreamEvents(rows)
if err != nil { if err != nil {
return nil, err return nil, err
@ -330,7 +330,7 @@ func (s *outputRoomEventsStatements) selectEarlyEvents(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed")
events, err := rowsToStreamEvents(rows) events, err := rowsToStreamEvents(rows)
if err != nil { if err != nil {
return nil, err return nil, err
@ -354,7 +354,7 @@ func (s *outputRoomEventsStatements) selectEvents(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed")
return rowsToStreamEvents(rows) return rowsToStreamEvents(rows)
} }

View File

@ -18,6 +18,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -134,7 +136,7 @@ func (s *outputRoomEventsTopologyStatements) selectEventIDsInRange(
} else if err != nil { } else if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEventIDsInRange: rows.close() failed")
// Return the IDs. // Return the IDs.
var eventID string var eventID string
@ -177,7 +179,7 @@ func (s *outputRoomEventsTopologyStatements) selectEventIDsFromPosition(
} else if err != nil { } else if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEventIDsFromPosition: rows.close() failed")
// Return the IDs. // Return the IDs.
var eventID string var eventID string
for rows.Next() { for rows.Next() {

View File

@ -19,6 +19,8 @@ import (
"context" "context"
"database/sql" "database/sql"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -102,7 +104,7 @@ func (s *accountDataStatements) selectAccountDataInRange(
if err != nil { if err != nil {
return return
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectAccountDataInRange: rows.close() failed")
var entries int var entries int

View File

@ -126,7 +126,7 @@ func (s *currentRoomStateStatements) selectJoinedUsers(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectJoinedUsers: rows.close() failed")
result := make(map[string][]string) result := make(map[string][]string)
for rows.Next() { for rows.Next() {
@ -154,7 +154,7 @@ func (s *currentRoomStateStatements) selectRoomIDsWithMembership(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectRoomIDsWithMembership: rows.close() failed")
var result []string var result []string
for rows.Next() { for rows.Next() {
@ -184,7 +184,7 @@ func (s *currentRoomStateStatements) selectCurrentState(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectCurrentState: rows.close() failed")
return rowsToEvents(rows) return rowsToEvents(rows)
} }
@ -238,7 +238,7 @@ func (s *currentRoomStateStatements) selectEventsWithEventIDs(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEventsWithEventIDs: rows.close() failed")
return rowsToStreamEvents(rows) return rowsToStreamEvents(rows)
} }

View File

@ -113,7 +113,7 @@ func (s *inviteEventsStatements) selectInviteEventsInRange(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
result := map[string]gomatrixserverlib.Event{} result := map[string]gomatrixserverlib.Event{}
for rows.Next() { for rows.Next() {
var ( var (

View File

@ -316,7 +316,7 @@ func (s *outputRoomEventsStatements) selectRecentEvents(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectRecentEvents: rows.close() failed")
events, err := rowsToStreamEvents(rows) events, err := rowsToStreamEvents(rows)
if err != nil { if err != nil {
return nil, err return nil, err
@ -343,7 +343,7 @@ func (s *outputRoomEventsStatements) selectEarlyEvents(
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() // nolint: errcheck defer common.CloseAndLogIfError(ctx, rows, "selectEarlyEvents: rows.close() failed")
events, err := rowsToStreamEvents(rows) events, err := rowsToStreamEvents(rows)
if err != nil { if err != nil {
return nil, err return nil, err
@ -372,7 +372,7 @@ func (s *outputRoomEventsStatements) selectEvents(
if streamEvents, err := rowsToStreamEvents(rows); err == nil { if streamEvents, err := rowsToStreamEvents(rows); err == nil {
returnEvents = append(returnEvents, streamEvents...) returnEvents = append(returnEvents, streamEvents...)
} }
rows.Close() // nolint: errcheck common.CloseAndLogIfError(ctx, rows, "selectEvents: rows.close() failed")
} }
return returnEvents, nil return returnEvents, nil
} }