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
Transactions hanging in AWS Lambda #2445
Comments
at least you are using trasactions wrong way. If you use implicit commit/rollback (return promise from transaction handler) you must not call trx.commit/trx.rollback manually. Anyways those problems would not cause the functionality you just described it would occur later on. Where did you find out |
Seems like an option to disable pool: https://github.com/tgriesser/knex/blob/45f5ffbad023e30eeb39162b4b743473f0188052/src/client.js#L51 Anyways, updated the code with your observations and using pool instead, still no luck, begins transaction but does not write or commit.
|
There are two ways of using transactions:
Both code snipets above use the second form, but in the last snipet commit is not called and therefore no write to the database occurs. The first snippet is correct according to the documentation, but in reality the knex.transaction do not return the result of the operation. Looking at the code, this makes sense - there could be multiple operations using transacting(trx) and it is not clear what should be returned. What worked for me was wrapping the knex.transaction inside a promise that was settled after the transaction block. To obtain the result of the operation, i define variables on the scope above the transaction block that are set after the operation executes. In this case this does not make much difference, since you are not using the result and just calling the callback. And I should point out that I did not run this code on aws lambda.
|
@okada I believe you are mistaken. There is absolutely no need to explicitly call
I'm willing to bet this is an error strictly in AWS Lambda, somehow.. What does |
@wubzz Yes, I you are right. I tested the example code from the docs and it works just fine. Thanks for correcting me. Will cleanup my code. |
@samin Did you ever figure out a way to make this work? I've encountered the same issue. Specifically in a Lambda environment the transaction emits |
@JQuezada0 not yet |
This is somewhat old conversation, but maybe this helps someone else. I too got stuck with lambda timing out on acquiring a connection, but only when using transactions. I had configured knex pool with only one connection (min=max=1) as recommended when used with Lambda. I looked up some knex transaction handling code, and started to suspect transactions might require a separate connection. I am not sure why it couldn't reuse the existing connection but all my troubles went away when I tried running my code with pool config min: 1, max: 2. Maybe give it a try. I think max: 1 is enough when you don't use transactions. |
Environment
AWS Lambda NodeJS 5.6 with AWS RDS
Knex version: 0.14.2
Database + version: MySQL 5.7.19
OS: Linux
Bug
Currently any query being made inside
knex.transaction
does not get executed, waiting to fail in timeout. In the example below, logs showWITH KNEX TRANSACTION
but notKNEX TRANSACTION BEGIN
. Ifknex.transaction
is removed, code works as expected, writing into theapplication
table. Am I missing something?The text was updated successfully, but these errors were encountered: