Skip to content
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

concurrent transaction throw deadlock error #1905

Open
wangsenyan opened this issue Nov 16, 2021 · 2 comments
Open

concurrent transaction throw deadlock error #1905

wangsenyan opened this issue Nov 16, 2021 · 2 comments

Comments

@wangsenyan
Copy link

wangsenyan commented Nov 16, 2021

pm2 start server with two instance ,

two instance connect one mysql server.

1637033091(1)

  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)

error

1637033134(1)

so,did i write the code ok ? thanks

it seem miss commit or rollback while concurrent

@achrinza
Copy link
Member

Hi @wangsenyan, thanks for opening an issue! Is this an error that occurs only with loopback-connector-mysql, or is it a broader issue that affects the base LoopBack Juggler?

@wangsenyan
Copy link
Author

sorry,i don't know,it too odd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants