mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
374 stars 91 forks source link

Records of transaction after commit are missing if noControlAfterUse is not set to true #164

Closed bc-m closed 3 years ago

bc-m commented 3 years ago

In our application, we get a connection from the pool, start a transaction, add a few records and commit them. After the commit, we release the connection. It looks like releasing the connection sporadically undoes the commit.

Our script (reduced to interactions with mariadb):

const conn = await pool.getConnection();
await conn.beginTransaction();

// insert rows
const res = await conn.query('XXX');
if(res.affectedRows < 1) throw new Error('insert failed');

await conn.commit();
await conn.release();

If we run this multiple times we missed about 1 of 5 transactions. How is that possible?

If we set noControlAfterUse in the pool configuration, all transactions are committed correctly.

Setup: MariaDB Database: 10.5 MariaDB Package: 2.5.4 NodeJS: 14 and 15

bc-m commented 3 years ago

With the debug log enabled, you can see that RESET statement is sent first before the COMMIT statement.

==> conn:1105470 Reset(0,5)
+--------------------------------------------------+
|  0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f |
+--------------------------------------------------+------------------+
| 01 00 00 00 1F                                   | .....            |
+--------------------------------------------------+------------------+

==> conn:1105470 Query(0,11)
+--------------------------------------------------+
|  0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f |
+--------------------------------------------------+------------------+
| 07 00 00 00 03 43 4F 4D  4D 49 54                | .....COMMIT      |
+--------------------------------------------------+------------------+
bc-m commented 3 years ago

Handled in Jira by MariaDB, see https://jira.mariadb.org/browse/CONJS-171?focusedCommentId=199581&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-199581. That's why I'm closing the ticket here.