loopbackio / loopbackio/loopback-datasource-juggler

concurrent transaction throw deadlock error

Open
#1,905 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs grooming
Dominant language
JavaScript
Stars
282
Forks
366
Avg merge
17h 4m
Merged PRs (30d)
10

Description

### pm2 start server with two instance ,
### two instance connect one mysql server.
![1637033091(1)](https://user-images.githubusercontent.com/30583832/141890334-01df1944-2366-4e09-aead-bfb3c9e18219.png)

```
Component.queue = async (obj, appId, projectId, accessToken) => {
const Project = Component.app.models.project;
const Page = Component.app.models.page;
const tx = await Project.beginTransaction({
isolationLevel: Project.Transaction.REPEATABLE_READ
});
const options = { transaction: tx };
try {
const userId = accessToken.userId;
const { pageId, data = [] } = obj;
const project = await Project.findOne({
where: { id: projectId, appId, ownerId: userId }
}, options);
const info = await Project.updateAll(
{ id: projectId },
{ lastUpdate: new Date() },
options
);

let page = await Page.findById(pageId, options);
let pages = await Page.find({
where: { projectId }
}, options)

pages.forEach(page => {
if (page.uuid)
idMap[page.uuid] = page.id;
})
let components = await Component.find(
{
where: { projectId, pageId: page.id },
fields: ["id", "uuid"]
}, options
)
await Page.updateAll({ id: page.id }, { isNeedGenerate: true }, options);
await tx.commit();
return { success: true };
} catch (err) {
if (tx) {
await tx.rollback();
}
};
```
**i use Jmeter test it , with 50 threads / sec, then throw error
but threads number small for example less than 10, they work well,
mysql deallock**

![1637032830(1)](https://user-images.githubusercontent.com/30583832/141890095-eac01720-e414-4c97-85d8-871ffee7680f.png)

error

![1637033134(1)](https://user-images.githubusercontent.com/30583832/141890399-3ee094c3-8108-4aef-a944-ba899534e164.png)

so,did i write the code ok ? thanks

it seem miss commit or rollback while concurrent

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the transaction code in the issue and reproduce the reported workload using two pm2 instances, MySQL, and the stated JMeter concurrency. Check whether the transaction is consistently committed or rolled back on every path; done means identifying the cause of the deadlock or confirming the application code is not responsible.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.