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
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?
Most helpful comment
looks like code in readme is incorrect, I'll fix that