knex: MySQL ECONNRESET

Environment

Knex version: 0.14.2 Database + version: MySQL 5.5.56 (ClearDB) OS: Windows 10 - Pro Node: 8.9.3

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do

After inactivity on a web app, I am receiving an ECONNRESET which after refreshing the page, appears to resolve the some connection issue. I am guessing it’s an issue of MySQL ending the connection and knex being unable to realize that.

  1. Error message Terminal: Knex:warning - Connection Error: Error: Connection lost: The server closed the connection.

Knex response:

select * from `tblcustomers` where `idCustomers` = 60381 - read ECONNRESET
Error: read ECONNRESET
    at _errnoException (util.js:1024:11)
    at TCP.onread (net.js:615:25)
    --------------------
    at Protocol._enqueue (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\mysql\lib\protocol\Protocol.js:145:48)
    at Connection.query (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\mysql\lib\Connection.js:208:25)
    at D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\knex\lib\dialects\mysql\index.js:156:18
    at Promise._execute (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\debuggability.js:303:9)
    at Promise._resolveFromExecutor (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\promise.js:483:18)
    at new Promise (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\promise.js:79:10)
    at Client_MySQL._query (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\knex\lib\dialects\mysql\index.js:150:12)
    at Client_MySQL.query (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\knex\lib\client.js:211:17)
    at Runner.<anonymous> (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\knex\lib\runner.js:149:36)
    at Runner.tryCatcher (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\util.js:16:23)
    at Runner.query (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\method.js:15:34)
    at D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\knex\lib\runner.js:61:21
    at tryCatcher (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\util.js:16:23)
    at D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\using.js:185:26
    at tryCatcher (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (D:\Users\Chris-PC\Documents\Web Design\KnexIssueTest\node_modules\bluebird\js\release\promise.js:512:31)
  1. Reduced test code, for example in https://npm.runkit.com/knex or if it needs real database connection to mysql or postgresql, then single file example which initializes needed data and demonstrates the problem.

My config:

const knex = require("knex")({
    client: 'mysql',
    connection: {
        host: '',
        user: '',
        password: '',
        database: '',
        //debug: true,
        pool: {
            min: 0,
            max: 2
        }
    }
});

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (16 by maintainers)

Most upvoted comments

Yep… looks like you should never keep idle connections in pool with cleardb. So maybe it starts working if you set your pool min to be 0 so that all idle connections will be discarded after idleTimeoutMillis.

After running the following code (which was provided in the other thread) with the connection to my ClearDB mysql database I got the error.

const knex = require('knex')({
    client: 'mysql',
    connection: {
        host: '',
        user: '',
        password: '',
        database: '',
        //debug: true,
        pool: {
            min: 2,
            max: 10
        }
    }
});

console.log(new Date());

const Bluebird = require('bluebird');
function periodOfTime () {
  return Bluebird.delay(1000 * 60 * 15);
}

async function main () {
  await knex.raw('select 1');
  await periodOfTime();
  await knex.raw('select 1');
}

main();
(node:16336) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: select 1 - read ECONNRESET
(node:16336) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.