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

Question: Transaction per request #9

Closed sykorax closed 5 years ago

sykorax commented 5 years ago

Hey,

I use Nestjs with Typeorm. I'm not sure it has a point when transaction comes into it. If node is fully non blocking what's the point of having a single connection but cannot have multiple transactions?

I see that only one transaction is allowed per connection but maybe a transaction queue could solve this problem.

So when two requests hit the same controller method and both requires a transaction the second request will fail since there's another active transaction.

Is this package able to solve this problem?

odavid commented 5 years ago

Hi, The goal of this library is to support transaction propagation between methods within the code in a simple manner.

As for your question: If 2 requests are hitting the same controller method, both will have different entityManager instances in different CLS-Hooked Namespace, so concurrency should be solved.

sykorax commented 5 years ago

Thanks for the quick response.

Well I initialize the namespace before the application start as your Readme mentions and I force my controller method to sleep with set timeout for some seconds. If even more requests come in in that time window typeorm says that I already have an active transaction so I'm not able to make a new one. Do you think it is because somehow I receive the same manager instance? :/

odavid commented 5 years ago

This is weird... I am using getManager()

Did you try to test your scenario with pure typeorm? These things can also happen because of different DB connection drivers, pools...

sykorax commented 5 years ago

Hmm.

I test against Sqlite. Maybe should try with sql server since production environment will be that one.

I'll have a look at this tomorrow. However since i use Nestjs all DI managed by that. So repositories and connections are managed by the Nest container. Do you have de facto experience with nest and typeorm transaction concurrency?

I would be very disappointed if it does not work but It should. Right?

odavid commented 5 years ago

Well, I don't have a lot of experience with Nest (played a bit)

It should work IMHO, but cannot vouch for that.

sykorax commented 5 years ago

Ah well I will check it out with sql server tomorrow. I'll let you know what's going on :D and thanks.

sykorax commented 5 years ago

Ok, so i have tested with mssql and works fine. It seems that sqlite does not support multiple transactions to be opened at the same time. However i found a thread at typeorm where some queue solution is under discussion.

Sorry for bothering you. Package is awesome! ^^,

odavid commented 5 years ago

Thanks!!!

alirezabonab commented 2 years ago

Ok, so i have tested with mssql and works fine. It seems that sqlite does not support multiple transactions to be opened at the same time. However i found a thread at typeorm where some queue solution is under discussion.

Sorry for bothering you. Package is awesome! ^^,

could you send the link to the Typeorm issue.