Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

pool.query fails after calling pool.end #1803

Copy link
Copy link
Closed
@HQidea

Description

@HQidea
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.