Node-mysql2: Pool execute won't release connection

Created on 20 Aug 2018  路  5Comments  路  Source: sidorares/node-mysql2

I have setup a pool like this:

pool = mysql.createPool({
  //host, port,etc...
  waitForConnections: false,
  queueLimit: 1,
  debug: false,
  namedPlaceholders: true,
  supportBigNumbers: true
});

I then try to run queries with pool.execute, which I assume should close connections automatically as query does according to docs:

// For pool initialization, see above pool.query(function(err, conn) { conn.query(/* ... */); // Connection is automatically released when query resolves })

However, it seems that the connections are left in sleep state (visible from information_schema.processlist) and once the connection limit (default 10) is reached, my code stops and waits until the database hits it's timeout (100 seconds) and kills the dangling connections, then again the next 10 queries run and so on...

Am I missing something? The database is MariaDB 10.2.16

Most helpful comment

looks like code in readme is incorrect, I'll fix that

All 5 comments

Follow this and you should be good...

Link: https://github.com/sidorares/node-mysql2/issues/840#issuecomment-415228661

this one is incorrect:

pool.query(function(err, conn) {
  // pool.query callback parameters are (err, rows, fields) 
  conn.query(/* ... */);
   // Connection is automatically released when query resolves
})

not sure how this works at all for you, conn in your code points to rows array and does not have .query() method. Can you double check the code you posted as example is the code you running?

If I'm not messing up things completely, that code is right from the Read.me?
https://github.com/sidorares/node-mysql2/blob/master/README.md#using-connection-pools

looks like code in readme is incorrect, I'll fix that

It looks like this has been fixed. Time to close this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abumusamq picture abumusamq  路  5Comments

jomel picture jomel  路  8Comments

HugoMuller picture HugoMuller  路  3Comments

DirkWolthuis picture DirkWolthuis  路  3Comments

MHDante picture MHDante  路  4Comments