N
N
nurzhannogerbek2019-03-13 08:19:00
MySQL
nurzhannogerbek, 2019-03-13 08:19:00

SequelizeConnectionError in Node.js app?

Hello comrades! Faced a strange problem, please help me figure it out.
There is a Node.js application. This application works with MySQL and PostgreSQL databases . Used the sequelize library to work with the previously mentioned databases. On the local machine (windows 10) the project works. I ran this project in a Docker container. Docker itself is on a CentOS server. The application worked for a couple of days without problems, but yesterday I noticed a problem. The application cannot connect to the MySQL database, but there are no problems connecting to PostgreSQL. As mentioned earlier, the local project connects to MySQL without any problems. I also connect without problems through the dbForge/DBeaver tools.
MySQL.js:

const Sequelize = require('sequelize');

const sequelize = new Sequelize('database_name', 'username', 'password', {
    host: 'host',
    dialect: 'mysql',
    pool: {
        max: 15,
        min: 5,
        idle: 20000,
        evict: 15000,
        acquire: 30000
    },
});

sequelize.authenticate().then(() => {
    console.log('Connection to database has been established successfully.');
}).catch(err => {
    console.error('Unable to connect to database:', err);
});

module.exports = sequelize;

routes.js:
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) => {
            res.status(200).send(locations)
        }).catch((error) => {
            res.status(400).send(error);
        });
    } else {
        return res.status(401).send({
            status: false,
            description: "Unauthorized"
        });
    }
});

Initially, I thought the problem was that sequelize didn't close connections/pools automatically. Therefore, I recreated the container several times to zero everything. Unfortunately the problem has not disappeared.
Could it be that the problem is in Docker itself?! What are your assumptions? By default, MySQL uses port 3306. Could it be that the Docker container somehow closed this port?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Ostanin, 2019-03-14
@bazilio91

Try replacing firewalld with iptables and reboot your machine. There is also a sense to refuse (for one) from userland proxy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question