sidorares / node-mysql2

:zap: fast mysqljs/mysql compatible mysql driver for node.js
https://sidorares.github.io/node-mysql2/
MIT License
4.04k stars 610 forks source link

Promise connection sync methods always proxy non-pool connection #672

Open c24w opened 6 years ago

c24w commented 6 years ago

This is an issue when using a PromiseConnection which wraps a PoolConnection. For example:

const {createPool} = require('mysql2/promise');
const pool = await createPool(options);
const connection = await pool.getConnection();
connection.destroy();

destroy only ever proxies Connection.prototype.destroy, not PoolConnection.prototype.destroy, so the connection isn't removed from the pool.

sidorares commented 6 years ago

thanks. Would you be able to make unit test covering this?

sidorares commented 6 years ago

do you think #674 fixed this @c24w ?

c24w commented 6 years ago

@sidorares #674 fixed the exact issue I was seeing; however, this is the more generic issue that connections originating from a PromisePool are inheriting methods from Connection, not PoolConnection. My PR addressed this for the destroy method, but there may be others.