Hopefully fix panics for good in SQLite this time

This commit is contained in:
Neil Alexander 2022-02-02 16:55:48 +00:00
parent 885c70c31c
commit d1baa305ae
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 17 additions and 6 deletions

View file

@ -40,11 +40,6 @@ type Transaction interface {
// You MUST check the error returned from this function to be sure that the transaction // You MUST check the error returned from this function to be sure that the transaction
// was applied correctly. For example, 'database is locked' errors in sqlite will happen here. // was applied correctly. For example, 'database is locked' errors in sqlite will happen here.
func EndTransaction(txn Transaction, succeeded *bool) error { func EndTransaction(txn Transaction, succeeded *bool) error {
if txn == nil {
// Sometimes in SQLite mode we have nil transactions. If that's the case
// then we are working outside of a transaction and should do nothing here.
return nil
}
if *succeeded { if *succeeded {
return txn.Commit() return txn.Commit()
} else { } else {

View file

@ -61,6 +61,22 @@ func NewRoomUpdater(ctx context.Context, d *Database, txn *sql.Tx, roomInfo *typ
}, nil }, nil
} }
// Implements sqlutil.Transaction
func (u *RoomUpdater) Commit() error {
if u.txn == nil { // SQLite mode probably
return nil
}
return u.txn.Commit()
}
// Implements sqlutil.Transaction
func (u *RoomUpdater) Rollback() error {
if u.txn == nil { // SQLite mode probably
return nil
}
return u.txn.Commit()
}
// RoomVersion implements types.RoomRecentEventsUpdater // RoomVersion implements types.RoomRecentEventsUpdater
func (u *RoomUpdater) RoomVersion() (version gomatrixserverlib.RoomVersion) { func (u *RoomUpdater) RoomVersion() (version gomatrixserverlib.RoomVersion) {
return u.roomInfo.RoomVersion return u.roomInfo.RoomVersion

View file

@ -649,7 +649,7 @@ func (d *Database) storeEvent(
if err != nil { if err != nil {
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("GetRoomUpdater: %w", err) return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("GetRoomUpdater: %w", err)
} }
defer sqlutil.EndTransactionWithCheck(updater.txn, &succeeded, &err) defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
} }
if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil { if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil {
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("updater.StorePreviousEvents: %w", err) return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("updater.StorePreviousEvents: %w", err)