Skip to content

Neo.ClientError.Cluster.NotALeader using Neo4j aura  #1207

Description

@nicholasoxford

Bug Report

After upgrading to a paid tier and when calling

    const graphDbResponse = await graphDb
      .session({ defaultAccessMode: neo4j.session.WRITE })
      .executeWrite((q) => q.run(query, params))
      .catch((err) => {
        console.error("Error adding follow to graph db", JSON.stringify(err));
      });
      
      // or
      
      const session = graphDb.session({
      defaultAccessMode: neo4j.session.WRITE,
    });

    session
      .run(query, params)
      .then(async (res) => {
        console.log("result", res);
        graphDbResponse = res;
        await session.close();
      })
      .catch((err) => {
        console.error("Error adding follow to graph db", JSON.stringify(err));
      });

with graphDB coming from

const graphDb = driver(
  GRAPH_DB_URL,
  auth.basic(GRAPH_DB_USERNAME, GRAPH_DB_PASSWORD)
);

I am getting the error: Neo.ClientError.Cluster.NotALeader about 50% of the time

I am currently using the bolt connection. Reading online it seems like I should be using neo4j+s connections, which I have tried both locally and in production with no success. I get this info from the get go

INFO Routing table is stale for database: "neo4j" and access mode: "WRITE": RoutingTable[database=neo4j, expirationTime=0, currentTime=1721796877254, routers=[], readers=[], writers=[]]

then when I try to query the database I get

ConnectionHolder got an error while releasing the connection. Error Neo4jError: Connection acquisition timed out in 60000 ms. Pool status: Active conn count = 0, Idle conn count = 0.. Stacktrace: Neo4jError:

My url is in this format GRAPH_DB_URL="neo4j+s://<DID>.databases.neo4j.io"

Here is where I am acquiring the session, I am assuming the name of the database is neo4j, I understand if I dont pass anything it just makes a call to look it up

const session = graphDb.session({
            database: "neo4j",
            defaultAccessMode: "WRITE",
          });
          console.log("ABOUIT TO CALL");
          const result = await session.run(query, { id }).catch((e) => {
            console.log({ e });
            throw e;
          });

How can I force it to write to the leader? Is there something wrong with how I am trying to connect?

My Environment

Javascript Runtime Version: Bun 1.20
Driver Version: 5.22.0
Neo4j Version and Edition: Neo4J Aura

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions