title: SequelizeConnectionError in Node.js application
body: <p>I have strange problem and don't know in what place is the problem. I will be grateful for any help.</p>
  
  <p>I have <strong>Node.js</strong> application which works fine in local windows 10 computer. I run this application successfully in <strong>Docker</strong> which is in CentOS server. This application works with remote MySQL and PostgreSQL databases. It worked correctly several days but yestoday I notice that I have error. Application can't connect to remote MySQL database anymore. In the same time I can connect to that remote MySQL database without any problem if I run application in my local computer or connect by DBeaver/dbForge tool.</p>
  
  <p><strong>MySQL.js</strong>:</p>
  
  <pre><code>const Sequelize = require('sequelize');
  
  const sequelize = new Sequelize('database_name', 'username', 'password', {
      host: 'host',
      dialect: 'mysql'
  });
  
  sequelize.authenticate().then(() =&gt; {
      console.log('Connection to database has been established successfully.');
  }).catch(err =&gt; {
      console.error('Unable to connect to database:', err);
  });
  
  module.exports = sequelize;
  </code></pre>
  
  <p><strong>routes.js</strong>:</p>
  
  <pre><code>const express = require('express');
  
  const router = express.Router();
  
  const sequelize = require('../configurations/MySQL');
  const Sequelize = require('sequelize');
  
  const passport = require('passport');
  require('../configurations/password')(passport);
  
  router.post('/search_by_name', passport.authenticate('jwt', {session: false}, null), function(req, res) {
      const token = getToken(req.headers);
      if (token) {
          sequelize.query("LONG SQL QUERY", {
              replacements: {
                  name: req.body.name,
              },
              type: Sequelize.QueryTypes.SELECT
          }).then((locations) =&gt; {
              res.status(200).send(locations)
          }).catch((error) =&gt; {
              res.status(400).send(error);
          });
      } else {
          return res.status(401).send({
              status: false,
              description: "Unauthorized"
          });
      }
  });
  </code></pre>
  
  <p>As you can see I use <a href="https://sequelize.readthedocs.io/en/v3/" rel="nofollow noreferrer">sequelize</a> library to connect application to remote MySQL database. The same library I use to connect to remote PostgreSQL database. As I said before error happens only when I try to connect to remote MySQL database in Docker. There is no error with PostgreSQL connection in Docker. Is it possible that problem inside Docker/network?</p>
  
  <p><strong>Dependencies</strong>:</p>
  
  <pre><code>"sequelize": "^4.42.0"
  "mysql2": "^1.6.4"
  </code></pre>
  
  <p>I also thought that the reason of the problem can be because of much pools/connections and sequelize library don't close them automatically. For thats why I restarted docker сontainer several times hoping to confirm the theory. Unfortunately the error do not disappear.</p>
  
  <p>How do you think, what happens?</p>
  
  <p><strong>Error</strong>:</p>
  
  <pre><code>Unable to connect to the database: { SequelizeConnectionError: connect ETIMEDOUT
      at Utils.Promise.tap.then.catch.err (/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:149:19)
      at tryCatcher (/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/node_modules/bluebird/js/release/promise.js:512:31)
      at Promise._settlePromise (/node_modules/bluebird/js/release/promise.js:569:18)
      at Promise._settlePromise0 (/node_modules/bluebird/js/release/promise.js:614:10)
      at Promise._settlePromises (/node_modules/bluebird/js/release/promise.js:690:18)
      at _drainQueueStep (/node_modules/bluebird/js/release/async.js:138:12)
      at _drainQueue (/node_modules/bluebird/js/release/async.js:131:9)
      at Async._drainQueues (/node_modules/bluebird/js/release/async.js:147:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/node_modules/bluebird/js/release/async.js:17:14)
      at processImmediate (timers.js:632:19)
    name: 'SequelizeConnectionError',
    parent:
     { Error: connect ETIMEDOUT
         at Connection._handleTimeoutError (/node_modules/mysql2/lib/connection.js:173:17)
         at listOnTimeout (timers.js:324:15)
         at processTimers (timers.js:268:5)
       errorno: 'ETIMEDOUT',
       code: 'ETIMEDOUT',
       syscall: 'connect',
       fatal: true },
    original:
     { Error: connect ETIMEDOUT
         at Connection._handleTimeoutError (/node_modules/mysql2/lib/connection.js:173:17)
         at listOnTimeout (timers.js:324:15)
         at processTimers (timers.js:268:5)
       errorno: 'ETIMEDOUT',
       code: 'ETIMEDOUT',
       syscall: 'connect',
       fatal: true }}
  </code></pre>