Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Transaction per request #9

Closed
sykorax opened this issue Mar 21, 2019 · 9 comments
Closed

Question: Transaction per request #9

sykorax opened this issue Mar 21, 2019 · 9 comments

Comments

@sykorax
Copy link

sykorax commented Mar 21, 2019

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
Copy link
Owner

odavid commented Mar 21, 2019

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
Copy link
Author

sykorax commented Mar 21, 2019

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
Copy link
Owner

odavid commented Mar 21, 2019

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
Copy link
Author

sykorax commented Mar 21, 2019

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
Copy link
Owner

odavid commented Mar 21, 2019

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

It should work IMHO, but cannot vouch for that.

@sykorax
Copy link
Author

sykorax commented Mar 21, 2019

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

@sykorax
Copy link
Author

sykorax commented Mar 22, 2019

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! ^^,

@sykorax sykorax closed this as completed Mar 22, 2019
@odavid
Copy link
Owner

odavid commented Mar 22, 2019

Thanks!!!

@alirezabonab
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants