Search code examples
mysqlnode.jsnode-mysql

When you call `release` instead `destroy` on connection?


I am asking about https://github.com/mysqljs/mysql . I am a bit puzzled what is the difference between destroy and release in practice. Consider such code:

pool.getConnection(function(err, conn)
{
  if (err)
    throw err;

  console.log("Connected");
  conn.release();
});

This will hang forever. If I switch release to destroy the program terminates. The example from the project page has such piece of code:

connection.release();
// Don't use the connection here, it has been returned to the pool.

So both are terminating-like only release is not terminating. My question is -- what is the use of release then?


Solution

  • As it appears, non-terminating state is intentional to keep the pool alive, and "cycle" the connections. For some batch job it is not that important. Here is the answer by sidorares: https://github.com/mysqljs/mysql/issues/1486