Deadlock found when trying to get lock; try restarting transaction
See original GitHub issueDescribe the bug
Deadlock occurs when multiple createProductVariants
calls are made at the same time.
Error: ER_LOCK_DEADLOCK: Deadlock found when trying to get lock; try restarting transaction:
{"response":{"errors":
[{"message":"ER_LOCK_DEADLOCK: Deadlock found when trying to get lock; try restarting transaction","locations":
[{"line":3,"column":9}],"path":["createProductVariants"]}],"data":null,"status":200},"request":{"query":"\n mutation
CreateProductVariants($input: [CreateProductVariantInput!]!) {\n createProductVariants(input: $input) {\n id\n sku\n }\n }\n","variables":{"input":[{"assetIds":["6374"],"featuredAssetId":"6374","sku":"010168240001","translations":
[{"languageCode":"fr","name":"CORONA EXTRA ONE WAY 35.5CL","customFields":{"content":""}},
{"languageCode":"nl","name":"CORONA EXTRA ONE WAY 35.5CL","customFields":{"content":""}}],"customFields":
{"pieces":1,"totalContent":0.36},"productId":"525","price":100000,"trackInventory":false,"taxCategoryId":"1","optionIds":
["776"]},{"assetIds":["6375"],"featuredAssetId":"6375","sku":"010168240006","translations":
[{"languageCode":"fr","name":"CORONA EXTRA ONE WAY 6X35.5CL","customFields":{"content":""}},
{"languageCode":"nl","name":"CORONA EXTRA ONE WAY 6X35.5CL","customFields":{"content":""}}],"customFields":
{"pieces":6,"totalContent":2.13},"productId":"525","price":100000,"trackInventory":false,"taxCategoryId":"1","optionIds":
["777"]}]}}}
Expected behavior A clear and concise description of what you expected to happen.
Environment (please complete the following information):
- @vendure/core version: 0.16.1
- Nodejs version: 12.18.3
- Database (mysql/postgres etc): mysql
Additional context Possible related issue: #242
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to avoid MySQL 'Deadlock found when trying to get lock
To avoid deadlock, you must then make sure that concurrent transactions don't update row in an order that could result in a deadlock....
Read more >Deadlock found when trying to get lock; try restarting transaction
When deadlock detection is enabled, InnoDB instantly detects it and rolls back one of the transactions. Otherwise, it relies on the ...
Read more >14.7.5.1 An InnoDB Deadlock Example
Within the transaction, A obtains an S lock on the row by selecting it in share mode: ... Deadlock found when trying to...
Read more >Trying To Debug "Deadlock found when trying to get lock
Ben Nadel noodles on the "Deadlock found when trying to get lock; try restarting transaction" error that he occasionally sees in MySQL.
Read more >Deadlock found when trying to get lock; try restarting ...
1 Answer 1 · Instead of IODKU, use INSERT IGNORE . Both will burn lots of AUTO_INCREMENT ids, but the latter is probably...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’re doing an automated import of products. Some background:
I created a new e2e test suite which makes parallel calls to operations designed to induce deadlock (example).
I then put in place retry logic in the code which wraps resolvers in a transaction, which seems to solve the issue (at least the e2e tests): https://github.com/vendure-ecommerce/vendure/blob/3b60bcbe72904342a747e16637bc4d5126f42564/packages/core/src/api/middleware/transaction-interceptor.ts#L60-L73 This will be available in 0.16.3 which will be released in the next day or so.