-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
mariadb transaction deadlock does not release connection #11571
Comments
Thanks for the detailed report. Can you wrap your code into a sequelize-sscce please? |
Sure, here's the PR: sequelize/sequelize-sscce#15 . I've also cleaned it up to use models rather than raw queries. |
Fantastic, thanks! |
I ran into this same issue. I can confirm the same lack of cleanup occurs on MySQL 5.7 as well. I can also confirm that it only seems to happen for deadlocks; other types of errors (lock wait timeouts, unique constraint errors) all cleaned up properly. |
Any word on this? I've been running with (I'm not sure if I have the right environment set up to properly test a PR.) |
I do the exact same thing and haven't seen any problems either. try {
// ...
} catch (e) {
if (e.parent && e.parent.code === 'ER_LOCK_DEADLOCK') {
(transaction as any).cleanup();
}
throw e;
} I tried to make a PR to fix it at one point, but was a little unclear as to where to put the cleanup, as the transaction-handling stuff seemed to be a little scattered around. I couldn't tell if I was going to accidentally double-clean-up a transaction and cause other errors. |
@sushantdhiman can you recommend the best way to address this? I can submit the PR |
Any update on this? I have made a PR to address this issue. |
As a hack for the time being, are there any downsides to running cleanup on every rolled back / failed transaction? |
I didn't realize there was an issue for this already! I fixed this in #12841 and our fix has been running in production on a fork of sequelize for the past few months. All it needs is a review. @prithvin is correct - we should run cleanup on every succeeded or failed transaction, and that fix ensures it happens. |
🎉 This issue has been resolved in version 6.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Issue Description
What are you doing?
Link to SSCCE PR: sequelize/sequelize-sscce#15
What do you expect to happen?
The second query in
t1
will wait fort2
, and the second query oft2
will result in a deadlock. After this,t2
should be rolled back, so we should have one available connection to startt3
.What is actually happening?
After one second of waiting, the timeout error is thrown for
t3
.Additional context
The problem seems to be these lines in
mariadb/query.js
:These mark the transaction as rolled back, but do not call
cleanup
to release the connection. (Addingt2.cleanup()
in the catch seems to solve the problem.)Environment
sequelize@5.19.8
v12.11.1
Issue Template Checklist
How does this problem relate to dialects?
Tested with mariadb, but the same lines appear in
mysql/query.js
.Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: