neo4j / neo4j-javascript-driver

Neo4j Bolt driver for JavaScript
https://neo4j.com/docs/javascript-manual/current/
Apache License 2.0
839 stars 148 forks source link

Routing Table/ Connection Timed out error #1158

Closed lalitkumar-pal-drishya closed 7 months ago

lalitkumar-pal-drishya commented 7 months ago

Hi Team, I'm using the enterprise edition of the neo4j aws cloud. I'm getting this error when setting maxConnectionPoolSIze as 1:

Connection acquisition timed out in 60000 ms. Pool status: Active conn count = 1, Idle conn count = 0.

And if I'm setting the maxConnectionPoolSIze greater than 1, we are getting this error:

{
  "errorType": "Neo4jError",
  "errorMessage": "Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=dbedcd75b117214a23950970bcb52c1df7, expirationTime=0, currentTime=1699275169006, routers=[], readers=[], writers=[]]",
  "trace": [
    "Neo4jError: Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=my_database, expirationTime=0, currentTime=1699275169006, routers=[], readers=[], writers=[]]",
    "",
    "    at captureStacktrace (/var/task/node_modules/neo4j-driver-core/lib/result.js:239:17)",
    "    at new Result (/var/task/node_modules/neo4j-driver-core/lib/result.js:59:23)",
    "    at Session._run (/var/task/node_modules/neo4j-driver-core/lib/session.js:174:16)",
    "    at Session.run (/var/task/node_modules/neo4j-driver-core/lib/session.js:139:21)",
    "    at /var/task/src/ingest_plant/create_pid.mjs:17:13",
    "    at /var/task/node_modules/p-limit/index.js:23:31",
    "    at run (/var/task/node_modules/p-limit/index.js:23:43)",
    "    at /var/task/node_modules/p-limit/index.js:45:20",
    "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
  ]
}

Bug Report

My Environment

Javascript Runtime Version: <!-- for instance, the output of node --version or the browser version --> Driver Version: Neo4j Version and Edition: Operating System:

bigmontz commented 7 months ago

@lalitkumar-pal-drishya, could you share information about your environment (JS Runtime, Driver version, Neo4j Version, etc) and share some logs? This error is quite general and it can be generated by a bunch of different situations. So, you will need to look through the logs or through the error cause (which are available since Neo4j Driver version 5.0.0 and Node version 16.9.0).

Alternatively, you can swap you protocol from neo4j to bolt(or neo4j+s to bolt+s, if encrypted) for getting a more detailed message.

lalitkumar-pal-drishya commented 7 months ago

@bigmontz Javascript Runtime Version: 18.x Driver Version: 4.0.3 Neo4j Version and Edition: 5 Enterprize edition.

driver function code

export async function getDriver() {
  let username;
  let password;
  let connection_string;
  if (process.env.LOCAL == 'true') {
    username = process.env.USER_NAME;
    password = process.env.PASSWORD;
    connection_string = process.env.CONNECTION_STRING;
  } else {
    const secrets = await get_secrets();
    username = secrets.username;
    password = secrets.password;
    connection_string = secrets.connection_string;
  }
  return neo4j.driver(connection_string, neo4j.auth.basic(username, password), {
    maxConnectionLifetime: 60 * 60 * 100000, // 1 hour
    maxConnectionPoolSize: 100,
    encrypted: 'ENCRYPTION_OFF',
  });
}

database creation code

export async function create_new_database(plant_id) {
  if (plant_id == '' || plant_id == null) {
    return {
      success: false,
      error: 'Invalid input',
    };
  }
  const database_name = 'db' + plant_id.replace(/[^a-zA-Z0-9\s]/g, '');
  const driver = await getDriver();
  const session = await get_default_database_session(driver);
  const result = await session.run('SHOW DATABASES');
  const database_list = [];
  let status;
  result.records.forEach((record) => {
    database_list.push(record._fields[0]);
  });
  if (database_list.includes(database_name)) {
    logger.info(`Database ${database_name} already exists`);
    status = {
      success: true,
      database_name: database_name,
    };
  } else {
    try {
      await session.run(`CREATE DATABASE ${database_name}`);
      logger.info(`Created database ${database_name}`);
      status = {
        success: true,
        database_name: database_name,
      };
    } catch (err) {
      logger.error(
        `Error creating new database ${database_name} error: ${err}`,
      );
      status = {
        success: false,
        error: err,
      };
    }
  }
  await closeSession(session);
  await closeDriver(driver);
  return status;
}

session code

export async function getSession(driver, plant_id) {
  const database_name = 'db' + plant_id.replace(/[^a-zA-Z0-9\s]/g, '');
  let session;
  try {
    if (driver)
      session = driver.session({
        database: database_name,
      });
    else session = (await getDriver()).session({ database: database_name });
  } catch (err) {
    logger.error(err);
    session = (await getDriver()).session({
      database: database_name,
    });
  }
  return session;
}

logs

I'm getting this error when setting maxConnectionPoolSIze as 1:

Connection acquisition timed out in 60000 ms. Pool status: Active conn count = 1, Idle conn count = 0.

And if I'm setting the maxConnectionPoolSIze greater than 1, we are getting this error:


{
  "errorType": "Neo4jError",
  "errorMessage": "Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=dbedcd75b117214a23950970bcb52c1df7, expirationTime=0, currentTime=1699275169006, routers=[], readers=[], writers=[]]",
  "trace": [
    "Neo4jError: Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=my_database, expirationTime=0, currentTime=1699275169006, routers=[], readers=[], writers=[]]",
    "",
    "    at captureStacktrace (/var/task/node_modules/neo4j-driver-core/lib/result.js:239:17)",
    "    at new Result (/var/task/node_modules/neo4j-driver-core/lib/result.js:59:23)",
    "    at Session._run (/var/task/node_modules/neo4j-driver-core/lib/session.js:174:16)",
    "    at Session.run (/var/task/node_modules/neo4j-driver-core/lib/session.js:139:21)",
    "    at /var/task/src/ingest_plant/create_pid.mjs:17:13",
    "    at /var/task/node_modules/p-limit/index.js:23:31",
    "    at run (/var/task/node_modules/p-limit/index.js:23:43)",
    "    at /var/task/node_modules/p-limit/index.js:45:20",
    "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
  ]
}
bigmontz commented 7 months ago

For enabling the logs in driver, you must:

const driver = neo4j.driver(theconnectionstring, theauth, {
   ...theOtherConfigs,
   logging: neo4j.logging.console('debug')
})

I recommend you update the driver to 5.14.0. The version 4.0.x of the driver is not homologated to work with the database 5. If you have to use the version 4.x of the driver because of compatibility issues with existing codebase, you might use the version 4.4.11.

bigmontz commented 7 months ago

Hey @lalitkumar-pal-drishya, did you update the driver? Did it solve the issue?

bigmontz commented 7 months ago

Issues closed due inactivity. Please, feel free to re-open the ticket in case of new evidences.