Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not perform discovery errors #111

Open
tgod009 opened this issue Feb 20, 2023 · 14 comments
Open

Could not perform discovery errors #111

tgod009 opened this issue Feb 20, 2023 · 14 comments

Comments

@tgod009
Copy link

tgod009 commented Feb 20, 2023

Code that's throwing error:

clients.map(async (client) => {
      let tenant = client.tenant;
      let clientId = client.client_id;
      let clientName = client.name;

      const query = new QuerySpecification()
        .withStatement(
          "MERGE(c:Client {client_id: '$clientId', app_name: '$clientName'})-[r:CLIENT_OF]->(t:Tenant {name: '$tenant'})'RETURN c, r, t'",
        )
        .bind([clientId, clientName, tenant]);
      await this.persistenceManager.execute(query);
  Full error
  
  Error: Cannot run query in this transaction, because it has already been committed.
at Function.withRootCause (/home/taylor/modsquad/cubeless-backend/app/node_modules/@liberation-data/src/DrivineError.ts:8:16)
at Transaction.query (/home/taylor/modsquad/cubeless-backend/app/node_modules/@liberation-data/src/transaction/Transaction.ts:51:32)
at TransactionalPersistenceManager.execute (/home/taylor/modsquad/cubeless-backend/app/node_modules/@liberation-data/src/manager/TransactionalPersistenceManager.ts:28:9)
at /home/taylor/modsquad/cubeless-backend/app/src/clients/clients.service.ts:54:7
@jasperblues
Copy link
Member

@tgod009 I have seen this error on recent Neo4j JS driver. Can you please try using the Neo4j driver directly? Does it work?

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

@jasperblues finally got around to trying with the neo4j driver directly and it worked. Any ideas why that is?

@jasperblues
Copy link
Member

@tgod009 are you able to share a sample where it works directly but not with drivine? That would be much appreciated and should certainly lead to a solution.

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

I just initalized the driver in my service file and called the session like so

const session = this.driver.session();
    session
      .run('Merge (a:Application {name: $appName})', {
        appName: createUserApplications.app_name,
      })
      .then((result) => {
        return result.records.map((record) => {
          return record.get('a');
        });
      })
      .catch((error) => {
        console.log(error);
      })
      .then(() => {
        session.close();
      });

@jasperblues
Copy link
Member

And the same thing does not work for you drivine @tgod009 ?

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

Running Drivine like this throws the routing table error

const query = new QuerySpecification()
      .withStatement('Merge(a:Application {name: $appName})')
      .bind(createUserApplications);
    return this.persistenceManager.execute(query);
 ERROR [ExceptionsHandler] Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=default database, expirationTime=0, currentTime=1679379048963, routers=[], readers=[], writers=[]]

@jasperblues
Copy link
Member

Here's what I did to make it work:

  • Clone the drivine repository (this one).
  • Copy .env.sampe to .env and change the neo4j password to appropriate pass.
  • Modify the file RouteRepository. Add this code:
    @Transactional()
    async createApp(name: string): Promise<void> {
        const query = new QuerySpecification()
            .withStatement('Merge(a:Application {name: $appName})')
            .bind({appName: name});
        return this.persistenceManager.execute(query);
    }

^-- Note that the params are slightly different. Since we bind name parameters we supply the name.

Final Step

Modify the RouteRepository.spec.ts. Add this test:

    it('should create an app', async () => {
        await repo.createApp("foobar")
    });

The test passes. If you want to see the result in the DB, at the top of that file change the following:

RunWithDrivine({rollback: false}); <-- change rollback to false

If you follow the approach above, does it work for you? The may be an issue but the above works for me.

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

That's with the sample application?

@jasperblues
Copy link
Member

No, I just added it to Drivine directly. You can clone that repo, create an env file, then run the tests.

Run this gist for most tests to pass: https://gist.github.com/jasperblues/7a6e774090c9ef0f18c44920b48b6b23

There are two tests that need additional setup steps. Don't worry about those, just add the code above and let me know what happens with your Neo4j server. If it works - it was a setup issue. If it does, its something environment related.

I was going to add to the sample app, but I think I need to freshen dependencies. (Will do shortly).

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

I gave it try and I got the same error using my db info

Error: Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=default database, expirationTime=0, currentTime=1679435963014, routers=[], readers=[], writers=[]]

@tgod009
Copy link
Author

tgod009 commented Mar 21, 2023

Side note not sure if this effects it but I'm using Aura not a local DB with the encrypted url

@jasperblues
Copy link
Member

@tgod009 I will see if I can reproduce with Aura.

@tgod009
Copy link
Author

tgod009 commented Mar 22, 2023

Not sure if this was causing it but I did just notice that I was using the non encrypted protocol

@jasperblues
Copy link
Member

If you can try with both and compare results that would be great. This is puzzling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants