sequelize / website

Our beloved website that contains all versions of our documentations and the API references.
https://sequelize.org
29 stars 154 forks source link

Clarify whether it is OK to fire concurrent queries using the same transaction #727

Open ksze opened 3 years ago

ksze commented 3 years ago

Issue Creation Checklist

[x] I have read the contribution guidelines

Issue Description

What was unclear/insufficient/not covered in the documentation

It is popular to write asynchronous code in JavaScript. And because sequelize.query is async and returns a Promise, it can be very tempting to write code like this:

await sequelize.transaction(async (transaction) => {
  await Promise.all([
    sequelize.query(query1, {transaction}),
    sequelize.query(query2, {transaction}),
    /* and more queries ... */
    sequelize.query(queryN, {transaction}),
  ]);
});

However, it is not entirely clear from the documentation whether this is supposed to work. I mean, this might accidentally work if the queries are all very short and quick. But what happens if some queries take longer than others? What if the queries are indirectly/implicitly related (e.g. query2 depending on some changes effected in the database by query1). Does sequelize automatically order the queries (in the order that the sequelize.query() calls were made), even though they look to be fired concurrently? Would the correct functioning depend on how async is implemented in the JavaScript runtime; would it work correctly in node.js but be dangerous in a hypothetical alternative JavaScript runtime that is still conformant to ECMA-262?

If possible: Provide some suggestion on how we can enhance the docs

Explicitly explain whether concurrent queries can work correctly (i.e. the way the programmer might expect), maybe under specific conditions - e.g. no indirect/implicit dependency among the queries.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

ksze commented 2 years ago

bump

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂