aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-10-14 17:05:09 +0100
committerGitHub <noreply@github.com>2020-10-14 17:05:09 +0100
commite3c2b081c7c197cad931d6525931dc9e960b93c3 (patch)
tree885aaeab8abedba67236697e47d34628beb35448 /roomserver
parent6f12b8f85c6e244b026df8016e60315e99603d9d (diff)
txn nil guard when rolling back LatestEventsUpdater (#1524)
* txn nil guard when rolling back LatestEventsUpdater * Spell lint correctly
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/storage/shared/latest_events_updater.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/roomserver/storage/shared/latest_events_updater.go b/roomserver/storage/shared/latest_events_updater.go
index 29eab0c9..b316f639 100644
--- a/roomserver/storage/shared/latest_events_updater.go
+++ b/roomserver/storage/shared/latest_events_updater.go
@@ -18,23 +18,30 @@ type LatestEventsUpdater struct {
currentStateSnapshotNID types.StateSnapshotNID
}
+func rollback(txn *sql.Tx) {
+ if txn == nil {
+ return
+ }
+ txn.Rollback() // nolint: errcheck
+}
+
func NewLatestEventsUpdater(ctx context.Context, d *Database, txn *sql.Tx, roomInfo types.RoomInfo) (*LatestEventsUpdater, error) {
eventNIDs, lastEventNIDSent, currentStateSnapshotNID, err :=
d.RoomsTable.SelectLatestEventsNIDsForUpdate(ctx, txn, roomInfo.RoomNID)
if err != nil {
- txn.Rollback() // nolint: errcheck
+ rollback(txn)
return nil, err
}
stateAndRefs, err := d.EventsTable.BulkSelectStateAtEventAndReference(ctx, txn, eventNIDs)
if err != nil {
- txn.Rollback() // nolint: errcheck
+ rollback(txn)
return nil, err
}
var lastEventIDSent string
if lastEventNIDSent != 0 {
lastEventIDSent, err = d.EventsTable.SelectEventID(ctx, txn, lastEventNIDSent)
if err != nil {
- txn.Rollback() // nolint: errcheck
+ rollback(txn)
return nil, err
}
}