Skip to content

Commit 2211313

Browse files
authored
Transaction fix (#151)
* fix: backport exponential backoff and retries * chore: changelog and version
1 parent ba10fef commit 2211313

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [2.4.1] - 2023-09-05
11+
12+
- Exponential backoff and increased retries for transactions
13+
1014
## [2.4.0] - 2023-03-30
1115

1216
- Support for Dashboard Search

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java-library'
33
}
44

5-
version = "2.4.0"
5+
version = "2.4.1"
66

77
repositories {
88
mavenCentral()

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public <T> T startTransaction(TransactionLogic<T> logic)
191191
@Override
192192
public <T> T startTransaction(TransactionLogic<T> logic, TransactionIsolationLevel isolationLevel)
193193
throws StorageTransactionLogicException, StorageQueryException {
194+
final int NUM_TRIES = 50;
194195
int tries = 0;
195196
while (true) {
196197
tries++;
@@ -231,9 +232,9 @@ public <T> T startTransaction(TransactionLogic<T> logic, TransactionIsolationLev
231232
// we have deadlock as well due to the DeadlockTest.java
232233
exceptionMessage.toLowerCase().contains("deadlock");
233234

234-
if ((isPSQLRollbackException || isDeadlockException) && tries < 3) {
235+
if ((isPSQLRollbackException || isDeadlockException) && tries < NUM_TRIES) {
235236
try {
236-
Thread.sleep((long) (10 + (Math.random() * 20)));
237+
Thread.sleep((long) (10 + (250 + Math.min(Math.pow(2, tries), 3000)) * Math.random()));
237238
} catch (InterruptedException ignored) {
238239
}
239240
ProcessState.getInstance(this).addState(ProcessState.PROCESS_STATE.DEADLOCK_FOUND, e);

0 commit comments

Comments
 (0)