Skip to content

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

@thenickdude

Description

@thenickdude

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions