CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

PoolConnection.release() returns a promise that is never resolved #77

Closed thenickdude closed 6 years ago

thenickdude commented 6 years ago

PoolConnection.release() returns a promise, but this promise is never resolved or rejected. This means that if you do something like:

mysqlPool.getConnection().then(connection => connection.release()).then(() => console.log("Here"));

"Here" will never be printed. Here's a full example:

let
  mysql = require("promise-mysql"),

  mysqlPool = mysql.createPool({
    host: "localhost",
    user: "test",
    password: "test",
    database: "test",
  });

mysqlPool.on("release", () => {
  console.log("The pool reports that release succeeded!");
});

mysqlPool.getConnection()
  .then(
    connection => {
      console.log("Releasing connection...");

      return connection.release()
        .then(
          () => console.log("Released successfully!"),
          () => console.log("Release failed!")
        );
    },
    err => {
      console.log("Failed to connect to MySQL " + err);
    }
  );

This prints "Releasing connection...", then "The pool reports that release succeeded!", but it never prints "Released successfully!" or "Release failed!".

Since the original PoolConnection.release() function didn't have a callback, I guess that the wrapped version is not supposed to be returning a promise. And indeed the user can work around it by avoiding using the promise from connection.release() to remove it from the promise chain:

mysqlPool.getConnection().then(connection => {
  connection.release();
}).then(() => console.log("Here"));

Correctly prints "Here" since the promise returned by release() is ignored.

CodeFoodPixels commented 6 years ago

Yep, completely valid. Will try and have a look this afternoon, cheers!

CodeFoodPixels commented 6 years ago

Fixed and published to npm in 3.1.4

thenickdude commented 6 years ago

Thanks!