I am having some race condition issues with an Aurora PostgreSQL DB hosted on AWS RDS. An example similar to what is happening is:
userEntranceLimits
.userId
and a column groupId
.count
of a UserEntrance's distinct users for a specific group may not exceed the group's userEntranceLimits
.I initially thought that the race condition was because of out-of-sync read replicas. However, if I am understanding this part of typeorm's code correctly, the transactions will always execute in master. Is that right? If that's the case, then I suppose the actual solution to the race condition is changing the isolation level of the transaction to something else, e.g. SERIALIZABLE
. Is any of this that I'm thinking true?
If you use it in way described in typeorm docs calling directly entityManager.transaction()
or @Transaction()
decorator and if you use connection, provided by transaction, then YES, transactions are using master.
As I debugged typeorm sources, while starting transaction, entityManager.queryRunner
is undefined
. So as per EntityManager implementation, queryRunner will be created for each transaction with no replication mode provided, so default (master) will be used.
So problem is more probable in your logic than in transaction configuration.