mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
366 stars 91 forks source link

Failed to create socket error #224

Closed gunsela92 closed 1 year ago

gunsela92 commented 1 year ago

Im using sequelize. Sometimes im getting this error i dont know why. How can i increase the timeout ?

    text: 'Connection timeout: failed to create socket after 1010ms',
    sql: null,
    fatal: true,
    errno: 45012,
    sqlState: '08S01',
    code: 'ER_CONNECTION_TIMEOUT'

My code ;

  const { host, port, user, password, database, poolMax, poolMin, dialect, acquire, idle } = config.database;
  const connection = await mariadb.createConnection({
    host: host,
    port: port,
    user: user,
    password: password,
    database: database,
    multipleStatements: true,
  });
  await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);

  // connect to db
  const sequelize = new Sequelize(database, user, password, {
    host: host,
    port: port,
    dialect: dialect,
    operatorsAliases: false,
    timeout: 10000,
    dialectOptions: {
      options: {
        requestTimeout: 60000,
        connectTimeout: 60000
      }
    },
    pool: {
      max: poolMax,
      min: poolMin,
      acquire: acquire,
      idle: idle,
    }
  });
rusher commented 1 year ago

As error indicate 'Connection timeout: failed to create socket after 1010ms', this correspond to connection timeout: option connectTimeout defaulting to 1000ms.

Option is set on sequelize, but not using direct connection

  const connection = await mariadb.createConnection({
    host: host,
    port: port,
    user: user,
    password: password,
    database: database,
    connectTimeout: 1000,
    multipleStatements: true,
  });

1000ms is quite a big time by default to create a connection, It's strange that you are facing this type of problem.

sorry for late answer.

rusher commented 1 year ago

closing issue, since this is not a bug, but documentation link request