-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Retry failing for implicit pool queries #176
Comments
Sounds like a simple fix. Are you available to raise a PR? |
Sorry, not used to dealing with flow. Would gladly help if it was plain js / TypeScript. |
There is nothing about this fix that requires knowing Flow. |
Hi @gajus , I'm interested to have a go at this one but need some guidance as I am fresh in this codebase. Like ivank I am not used to some of the conventions/structure of the codebase so please "go easy on me" if I am a bit "off". The problem
How to fix if (!connection.connection.slonik.transactionQueries) {
connection.connection.slonik.transactionQueries = []
}
connection.connection.slonik.transactionQueries.push({
executionContext,
executionRoutine,
sql: actualQuery.sql,
values: actualQuery.values,
})
If you have a few minutes, could you please provide any feedback? Thanks for your time. |
@oh-wo if you can add a failing test case to integration, I will make the necessary changes to make it work. |
Thanks; I will aim to open a PR in the next 1-2 weeks. |
Hey Gajus, Just to follow up and apologise for the delay; I am not sure when I will get to this, despite it being on my mind. |
I'm trying to fix this before fixing #163 but I'm a bit unsure what the best way to fix it is. My initial idea was to only retry the query that failed but I don't see a way to tell if the query is part of a transaction that was started by executing a 'begin' query without using the transaction method. If it is part of a transaction then retrying the query will not work. I also don't think that using The last possible solution I can think of is to fix the code so that it doesn't retry if we are not within a transaction started by the transaction method. This way the code will not throw the @gajus unless you have something against my first idea I will just implement that and trust that the users will not start transactions without using the transaction method. |
That's a reasonable assumption. |
Move transaction retry handling to the transaction and nestedTransaction methods and change it so that the handler function is called again instead of just replaying the queries that are part of the transaction. Fixes gajus#163. Add a second parameter to the transaction method to allow users to define a retry limit per transaction. If a retry limit is given for a transaction then the global defined retry limit for transactions is ignored. Change executeQuery so that it retries individual queries that failed with a transaction rollback error. Only queries that are not part of a transaction are retried. The number of times a query is retried is specified by the global queryRetryLimit configuration. Fixes gajus#176. The above change also fixes gajus#196 since the transactionQueries array no longer exists.
Move transaction retry handling to the transaction and nestedTransaction methods and change it so that the handler function is called again instead of just replaying the queries that are part of the transaction. Fixes #163. Add a second parameter to the transaction method to allow users to define a retry limit per transaction. If a retry limit is given for a transaction then the global defined retry limit for transactions is ignored. Change executeQuery so that it retries individual queries that failed with a transaction rollback error. Only queries that are not part of a transaction are retried. The number of times a query is retried is specified by the global queryRetryLimit configuration. Fixes #176. The above change also fixes #196 since the transactionQueries array no longer exists. BREAKING CHANGE: changes query / transaction retry strategy
🎉 This issue has been resolved in version 25.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
When using
pool.query
and Postgres throws an error, for exampledeadlock detected
, code40P01
slink attempts a retry. It is possible to have a deadlock even when executing a normal update query, not just a transaction.Expected Behavior
We should retry the implicit query.
Current Behavior
The query mechanism seems to assume there are transactionQueries and we end up with
transactionQueries is not iterable
error. (In node_modules/slonik/dist/routines/executeQuery.js:32:38)Steps to Reproduce
Execute several update queries that would deadlock, using implicit
pool.query
Logs
If I set
transactionRetryLimit: 0
, I get:The text was updated successfully, but these errors were encountered: