"throw er; // Unhandled 'error' event" when authenticate to a disable server.
See original GitHub issueI 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:
- Created 5 years ago
- Comments:5 (4 by maintainers)
🎉 This issue has been resolved in version 5.3.5 🎉
The release is available on:
Your semantic-release bot 📦🚀
Duplicate of https://github.com/sequelize/sequelize/issues/10406