typeorm-transactional-cls-hooked icon indicating copy to clipboard operation
typeorm-transactional-cls-hooked copied to clipboard

Transaction(s) stuck after connection limit reached

Open st1906 opened this issue 2 years ago • 2 comments

Hi, lets say we have the following

@transactional(PROPAGATION.REQUIRED)
create(){
 // insert something to DB
}

And the max connection limit set in typeorm is reached (lets say 2)

calling the method twice like this

await Promise.all([myService.create(), myService.create()])

produces the following logs and makes the service unable to do any additional queries to the DB.

Transactional@1675616291035|default|create|undefined|REQUIRED - Before starting: isCurrentTransactionActive = undefined
Transactional@1675616291037|default|create|undefined|REQUIRED - Before starting: isCurrentTransactionActive = undefined
query: START TRANSACTION
Transactional@1675616291035|default|create|undefined|REQUIRED - runWithNewTransaction - set entityManager in context: isCurrentTransactionActive: true
query: START TRANSACTION
Transactional@1675616291037|default|create|undefined|REQUIRED - runWithNewTransaction - set entityManager in context: isCurrentTransactionActive: true

It looks like when the pool size is reached, the methods try to create transactions and lock each other(?). Setting the PROPAGATION to mandatory makes it work. If anyone has a better understanding what is happening (and if this is expected behavior?), would appreciate an answer. (Same issue can be reproduced if the connection limit is raised at 5 or 10, and 5 or 10 calls are made)

Thanks!

st1906 avatar Feb 05 '23 17:02 st1906