odavid / typeorm-transactional-cls-hooked

A Transactional Method Decorator for typeorm that uses cls-hooked to handle and propagate transactions between different repositories and service methods. Inpired by Spring Trasnactional Annotation and Sequelize CLS
MIT License
524 stars 86 forks source link

Transaction(s) stuck after connection limit reached #115

Open st1906 opened 1 year ago

st1906 commented 1 year ago

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!