Skip to content

pool.query fails after calling pool.end #1803

Closed
@HQidea

Description

@HQidea

Sometimes, I need to close the old pool each 5 mins and create a new one. So I can't make sure pool.end is called after all queries end. Since it is said

The end method takes an optional callback that you can use to know once all the connections have ended. The connections end gracefully, so all pending queries will still complete and the time to end the pool will vary.

in the doc, I think I can just call pool.end any time I want, but I will occasionally get an error:

Error: Pool is closed.

So,
What does pending queries mean in the doc?
Is a query which have been called pool.query a pending query?

For example,

var mysql = require('mysql');
var pool  = mysql.createPool({
  connectionLimit : 10,
  host            : 'example.org',
  user            : 'bob',
  password        : 'secret',
  database        : 'my_db'
});

pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});
pool.end();  // will be called somewhere else, but will raise the same error here

I've found this commit 76de66e fixed pool.getConnection race conditions, but I don't quite understand what are the race conditions here. In my opinion, after I have called pool.query, this query is a pending query no matter what phase the operation is under the hood such as ping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions