question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"throw er; // Unhandled 'error' event" when authenticate to a disable server.

See original GitHub issue

I have many databases and want to connect them simultaneously in my application. Some of them may be disable at some moment. When I use the “sequelize.authenticate” command to connect and save them to the variable “sequelizes” some of them connect errors. I use async await and try to catch but finally loop still get the error.

What are you doing?

var sequelizes = [];

const getSequelize = async (server) => {

    let sequelize = new Sequelize({
        database: server.database,
        username: server.username,
        password: server.password,
        host: server.host,
        port: server.port ,
        dialect: "mssql",
        logging: false,
        // operatorsAliases: false,
        define: {
            freezeTableName: true,
            timestamps: false
        },
        dialectOptions: {
            encrypt: true,
            requestTimeout: 200000
        },
    });

    try {
        await sequelize.authenticate();
        console.log('Connected to ' + server.name);
        return [null, sequelize];
    } catch (err) {
        return [err];
    }
}

for (const server of servers) {
        const [err, sequelize] = await getSequelize(server);
        if (err) {
            console.log(err.message);
            continue;
        }
        sequelizes.push(sequelize);
}

What do you expect to happen?

events.js:167 throw er; // Unhandled ‘error’ event ^ ConnectionError: Connection lost - connect ETIMEDOUT xxxxx:xxx at ConnectionError (/…/node_modules/tedious/lib/errors.js:13:12) at Connection.socketError (/…/node_modules/tedious/lib/connection.js:1151:26) at Connector.execute (/…/node_modules/tedious/lib/connection.js:988:21) at Socket.onError (/…/node_modules/tedious/lib/connector.js:30:7) at Socket.emit (events.js:182:13) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) at process._tickCallback (internal/process/next_tick.js:63:19) Emitted ‘error’ event at: at Connection.socketError (/…/node_modules/tedious/lib/connection.js:1151:12) at Connector.execute (/…/node_modules/tedious/lib/connection.js:988:21) [… lines matching original stack trace …] at process._tickCallback (internal/process/next_tick.js:63:19)

What is actually happening?

Dialect: mssql Dialect version: tedious@5.0.3 Database version: SQL Server 2014 Sequelize version: sequelize@5.1.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sushantdhimancommented, Apr 12, 2019

🎉 This issue has been resolved in version 5.3.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
sushantdhimancommented, Mar 29, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

ExpressJS - throw er Unhandled error event - Stack Overflow
EADDRINUSE means that the port is already in use. try changing what port the web server in app.js listens on or kill whatever...
Read more >
How to Fix "throw er; // Unhandled 'error' event"?
It's only affecting watch -command and appears to be linked to a file-system incompatibility when watching file changes. The line number ...
Read more >
How to Fix “throw er; // Unhandled 'error' event”? - Medium
Try to install above npm package. It has resolved my issue. If it doesn't help then it may be cache problem. You can...
Read more >
2 Server Error Message Reference - MySQL :: Developer Zone
2018-10-02T03:20:39.410387Z 768 [ERROR] [MY-010045] [Server] Event Scheduler: ... Message: Host '%s' is not allowed to connect to this MySQL server. Error ...
Read more >
Unstable behavior when using useUnifiedTopology
events.js:174. throw er; // Unhandled 'error' event. ^. Error: read ECONNRESET. at TCP.onStreamRead (internal/stream_base_commons.js:111:27).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found