-
Notifications
You must be signed in to change notification settings - Fork 217
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
Recover from idle_in_transaction_session_timeout #680
Comments
This is from invalid transaction usage, as the author indicated so himself. |
I don't see why this issue is closed: IMHO it is clear that pg-postgres is currently not handling the So maybe you can give me some thints on how to get the error-code (and not just the error-text) in the |
I thought the issue was sorted. Just so, this library does not handle |
Well, the specific issue in our app is fixed. But I think it's just too easy that such an issue can slip into the application code again in the future. And then it would be great to have the I'll check node-postgres and their issue-list when I find some time. |
This is an unusual issue, and is the first time I ever hear about it. And if you can detect it for a specific transaction code, you can force the physical connection to be released, using the following synthetic approach: async function specialTransaction() {
const obj = await db.connect(); // manually allocating the connection
let idleTxIssueFound = false;
let txData;
try {
txData = await obj.tx(async t => {
// execute the transaction, and detect the idle issue, if possible
idleTxIssueFound = true; // if found an issue
});
} catch(e) {
} finally() {
// passing true into method `done` will force physical release of the connection
obj.done(idleTxIssueFound);
return txData;
}
} This is more of a proof of concept though. |
After checking some code and issues of node-postgres, I think my initial assumption was wrong. We will never receive error-code
I think whenever this error happens (for whatever reason - not only when Since node-postgres only returns an error string, and no error-code or error-class that can be checken, the only way to handle this case is to check the text of the error-message. There are many related issues in node-postgres:
and in node-pg-pool: |
It's a tough one to tackle. I mean, there is not good fix from this end, by the sound of it. |
I can also make the test work without checking the error-string and use e.g. change line 59 of function That is for sure better, but maybe the underscore in the variable name |
This does look like a hack-fix, i.e. should work in the current implementation of the client, but may get broken later, as we use a private variable. |
That's what I think too: maybe the node-postgres guys will make this pubilc: see node-postgres #2026 |
I think a more appropriate request would be to make the pool automatically release non-queryiable clients. Asking to make a private variable into public isn't a good idea in this case, it's just too low-level for what you are trying to achieve with this. I will think a little more about it, and perhaps will add that hack-fix, for now. |
@tmtron Before I make a change, since I cannot reproduce the issue on my side, can you check something for me, please... When this issue occurs, does the query throw an error? Because if it does, then the best place to amend the code is within isConnectivityError function. And if the query does not throw an error, then I will have to amend the connect method. |
Really? So the reproduction test-case works on your side?
The first query that is run after the timeout will throw the error string The current version of pg-promise will not recover from this and also the 2nd query in the test will throw the same error-message (because the broken connection, which is not queryable anymore, is reused). |
@tmtron Sorry for the late response. I can indeed see the issue from the test you provided. Here I simplified it, enough to still see the issue. I'm not sure about the proper fix yet. Will get back to it. |
For now, I have created a branch tx-idle-timeout to experiment with this. @tmtron If you have a suggestion, please do follow up ;) |
@vitaly-t Thanks for looking into this. Unfortunately I have no idea why the broken connection is not removed and reused in the next query. |
@tmtron I think I have solved it with this commit, to force killing every connection that's non-queryable. Can you give it a go to confirm the fix (it is now in the Wow, noticed just now your comment above, as we published almost at the same time :) So it looks like in the end we came to the same conclusion 😄 I will make a new release shortly. |
Released the fix in v10.3.5. |
@vitaly-t I've just updated to 10.3.5 and it works for me. All our tests are okay. |
Hi, I upgraded to 10.3.5, and now I did not see error message The stacktrace I have in my logs looks like
Environmen
|
@zhanghuancs That sounds like an issue related to keeping a connection open, which might something to do with your hosting environment. This is not related to the original issue here. |
@tmtron The underlying driver just took in the recommended change for dumping non-queryable connections. This means the functionality added here will be removed in a new official release that starts using that branch. That probably will be version 11. |
Hi, @vitaly-t Thank you for the response. I'm using AWS Lambda and follow the instruction here to reuse database connection using AWS Lambda. This might be the issue related to keeping a connection open as you said. Is there a way in pgpromise that I can get the open connection and kill this specific connection? Besides, is it possible that this issue is related to this thread, and it's quoted that the Any help would be appreciated! Thanks. |
@vitaly-t Hi, I think there is a regression in this item. I'm importing a big amount of data with a complex query from one remote server to another using this method: https://github.com/vitaly-t/pg-promise/wiki/Data-Imports#massive-inserts with, v10.4.4 I'm getting this error: |
@Gustav0ar Could you, please, re-try, using the latest Beta version? I am currently updating it, before v10.5.0 release. |
@vitaly-t Apparently it is working fine with the beta version. I'll update if I find any issues |
@vitaly-t still seeing the issue on |
Expected behavior
After an idle_in_transaction_session_timeout, the used connection will be working properly when used again from the pool.
Actual behavior
After a statement timeout in transaction, the used connection will be "broken" and new queries will not work. The error-message is
Client has encountered a connection error and is not queryable
Steps to reproduce
I've added a test-case to my project fork
Environment
Related
Notes
I thought that adding another check to isConnectivityError for code
25P03
(see postgres error codes) should work, but it does not. In this case theerr
parameter has nocode
property, but amessage
string.A nasty workaround for now is to check this
message
string:The text was updated successfully, but these errors were encountered: