node-orm-transaction icon indicating copy to clipboard operation
node-orm-transaction copied to clipboard

Transactions do not work together with connection pooling

Open TiddoLangerak opened this issue 12 years ago • 8 comments

I've noticed that when using the pooling option in node-orm2 that transactions don't work anymore. The source code of node-orm revealed that when pooling is used a new (or cached) connection is requested for every query executed (both for postgres and mysql). However, this also happens for queries inside a transaction. Therefore queries are executed using different connections and as a result these queries are no longer inside one transaction. Transactions should all be executed over one connection and a connection in a transaction should not be used for other queries as well.

One possible solution for this problem is that queries can be passed a connection/transaction object, such that users can manually group queries together in one transaction. Also, the connection used for a transaction should be removed from the pool as soon as the transaction starts and should be re-added as soon as the transaction is finished. This does require some modifications in the node-orm module however.

I'm happy to help fixing this problem, but since a solution to this problem requires modifying quite some code both in the node-orm module and most likely changes to the interface of either node-orm or this module it seemed best to me to discuss this first with you.

TiddoLangerak avatar Jul 15 '13 13:07 TiddoLangerak

Thank you for pointing this out, it's actually not simple to solve. I have to look at it more closely. The Driver class has to change to be able maybe to force a connection handler or something and don't dispose it..

dresende avatar Jul 15 '13 14:07 dresende

I was thinking about this and perhaps the "simplest" way is to change the mysql driver in orm to get a connection and keep it for a while. If a period of inactivity occurs, it just drops the link. If you keep using it it just keeps it.

dresende avatar Jul 20 '13 23:07 dresende

Any progress about this issue ?

taoyuan avatar Aug 04 '13 08:08 taoyuan

Hi, has there been any progress on this? I'm running into the same issue.

dirkmc avatar Dec 27 '13 00:12 dirkmc

I'm running into the same issue

odirus avatar Feb 28 '15 02:02 odirus

same issue here..

oriweingart avatar Jan 05 '16 13:01 oriweingart

+1

cjnqt avatar Mar 08 '16 10:03 cjnqt

+1

vulgarcoder avatar Feb 08 '17 11:02 vulgarcoder