Skip to content

Commit

Permalink
fix: fix rolling back expired transaction (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnagydavid authored Oct 23, 2024
1 parent 426ef20 commit bcb6753
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/datastore.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
await fn(tx)
await datastoreTx.commit()
} catch (err) {
await datastoreTx.rollback()
await this.rollback(datastoreTx)
throw err
}
}
Expand Down Expand Up @@ -549,6 +549,19 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
},
}
}

/**
* Silently rollback the transaction.
* It may happen that transaction is already committed/rolled back, so we don't want to throw an error here.
*/
private async rollback(datastoreTx: Transaction): Promise<void> {
try {
await datastoreTx.rollback()
} catch (err) {
// log the error, but don't re-throw, as this should be a graceful rollback
this.cfg.logger.error(err)
}
}
}

/**
Expand Down

0 comments on commit bcb6753

Please sign in to comment.