aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-08-28 13:28:40 +0100
committerGitHub <noreply@github.com>2020-08-28 13:28:40 +0100
commitc42c70597cf4b477a498e42188b2b32327bb758c (patch)
treed13eeb0f786a859ebf1bbc08bf2806ea862e3215 /syncapi/storage
parentfee1c227905530c9a941cc83425de69dec4c25ba (diff)
Add some error wrapping to sync API, use background context for sync (#1363)
* Add some error wrapping to sync API * Don't use request context for BeginTx until mattn/go-sqlite3#764 is fixed
Diffstat (limited to 'syncapi/storage')
-rw-r--r--syncapi/storage/shared/syncserver.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go
index ad0c1d99..401bae33 100644
--- a/syncapi/storage/shared/syncserver.go
+++ b/syncapi/storage/shared/syncserver.go
@@ -451,7 +451,7 @@ func (d *Database) addPDUDeltaToResponse(
wantFullState bool,
res *types.Response,
) (joinedRoomIDs []string, err error) {
- txn, err := d.DB.BeginTx(ctx, &txReadOnlySnapshot)
+ txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
if err != nil {
return nil, err
}
@@ -577,20 +577,23 @@ func (d *Database) IncrementalSync(
joinedRoomIDs, err = d.addPDUDeltaToResponse(
ctx, device, r, numRecentEventsPerRoom, wantFullState, res,
)
+ if err != nil {
+ return nil, fmt.Errorf("d.addPDUDeltaToResponse: %w", err)
+ }
} else {
joinedRoomIDs, err = d.CurrentRoomState.SelectRoomIDsWithMembership(
ctx, nil, device.UserID, gomatrixserverlib.Join,
)
- }
- if err != nil {
- return nil, err
+ if err != nil {
+ return nil, fmt.Errorf("d.CurrentRoomState.SelectRoomIDsWithMembership: %w", err)
+ }
}
err = d.addEDUDeltaToResponse(
fromPos, toPos, joinedRoomIDs, res,
)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("d.addEDUDeltaToResponse: %w", err)
}
return res, nil
@@ -632,7 +635,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
// a consistent view of the database throughout. This includes extracting the sync position.
// This does have the unfortunate side-effect that all the matrixy logic resides in this function,
// but it's better to not hide the fact that this is being done in a transaction.
- txn, err := d.DB.BeginTx(ctx, &txReadOnlySnapshot)
+ txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
if err != nil {
return
}
@@ -719,7 +722,7 @@ func (d *Database) CompleteSync(
ctx, res, device.UserID, numRecentEventsPerRoom,
)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("d.getResponseWithPDUsForCompleteSync: %w", err)
}
// Use a zero value SyncPosition for fromPos so all EDU states are added.
@@ -727,7 +730,7 @@ func (d *Database) CompleteSync(
types.NewStreamToken(0, 0, nil), toPos, joinedRoomIDs, res,
)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("d.addEDUDeltaToResponse: %w", err)
}
return res, nil
@@ -753,7 +756,7 @@ func (d *Database) addInvitesToResponse(
ctx, txn, userID, r,
)
if err != nil {
- return err
+ return fmt.Errorf("d.Invites.SelectInviteEventsInRange: %w", err)
}
for roomID, inviteEvent := range invites {
ir := types.NewInviteResponse(inviteEvent)