question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deadlock found when trying to get lock; try restarting transaction

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thomas-advantitgecommented, Oct 31, 2020

We’re doing an automated import of products. Some background:

  • The first importer version was using the fast importer. However we have a quite complex integration with an external system, requiring import of categories, stores, prices,…
  • The second version was running as a plugin injecting Vendure services. This worked, although we sometimes missed some functionality which was handled in Vendure resolvers.
  • In our current version we’re using the GraphQL interface to insert data. Important note here is that an import request from the external system will contain 1 product, collection, channel,… to be created or updated. In this test phase however, we’re importing a large dump of data through a script which calls the endpoints in a loop, in order to be able to simulate the same behaviour as if the external system would send data. This however takes a lot of time, especially when uploading assets as well. Therefore, we tried inserting the data in parallel (2 or 4 batches), causing the deadlocks. For the import script, it was easily be solved by just being patient and running sequentially. However, as we’re just using the API, this will most likely also happen in production occasionally.
0reactions
michaelbromleycommented, Nov 4, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found