diff options
author | oliverpool <3864879+oliverpool@users.noreply.github.com> | 2020-08-25 14:11:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-25 13:11:52 +0100 |
commit | a4db43e0969125db899dae465daf3ab1385c8ce9 (patch) | |
tree | a6fa17159a4a5e066b56751c849edba628b710e9 /syncapi | |
parent | c8b873abc8cb20227774c648b7a774214c8f3752 (diff) |
Don't overwrite global err before return (#1293)
Signed-off-by: Olivier Charvin <git@olivier.pfad.fr>
Diffstat (limited to 'syncapi')
-rw-r--r-- | syncapi/consumers/keychange.go | 5 | ||||
-rw-r--r-- | syncapi/storage/shared/syncserver.go | 18 |
2 files changed, 6 insertions, 17 deletions
diff --git a/syncapi/consumers/keychange.go b/syncapi/consumers/keychange.go index e14d2223..ee95e09d 100644 --- a/syncapi/consumers/keychange.go +++ b/syncapi/consumers/keychange.go @@ -95,9 +95,8 @@ func (s *OutputKeyChangeEventConsumer) updateOffset(msg *sarama.ConsumerMessage) } func (s *OutputKeyChangeEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { - defer func() { - s.updateOffset(msg) - }() + defer s.updateOffset(msg) + var output api.DeviceMessage if err := json.Unmarshal(msg.Value, &output); err != nil { // If the message was invalid, log it and move on to the next message in the stream diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 699a6647..4031dc74 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -455,13 +455,8 @@ func (d *Database) addPDUDeltaToResponse( if err != nil { return nil, err } - var succeeded bool - defer func() { - txerr := sqlutil.EndTransaction(txn, &succeeded) - if err == nil && txerr != nil { - err = txerr - } - }() + succeeded := false + defer sqlutil.EndTransactionWithCheck(txn, &succeeded, &err) stateFilter := gomatrixserverlib.DefaultStateFilter() // TODO: use filter provided in request @@ -641,13 +636,8 @@ func (d *Database) getResponseWithPDUsForCompleteSync( if err != nil { return } - var succeeded bool - defer func() { - txerr := sqlutil.EndTransaction(txn, &succeeded) - if err == nil && txerr != nil { - err = txerr - } - }() + succeeded := false + defer sqlutil.EndTransactionWithCheck(txn, &succeeded, &err) // Get the current sync position which we will base the sync response on. toPos, err = d.syncPositionTx(ctx, txn) |