neo4j / neo4j-javascript-driver

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

[QUESTION] Unable to connect to Neo4j Desktop graph instance #560

Open es50678 opened 4 years ago

es50678 commented 4 years ago

index.js

const neo4j = require('neo4j-driver');

const driver = neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'root'));

driver.session().run('CREATE (:Category {name: "verification" })')
  .then((results) => {
    console.log(results);
  }).catch((errors) => {
  console.log(errors);
});

I'm starting my Neo4j instance from Neo4j Desktop. The following is the log output when the instance starts:

2020-04-27 22:03:59.409+0000 INFO  ======== Neo4j 4.0.1 ========
2020-04-27 22:03:59.418+0000 INFO  Starting...
2020-04-27 22:04:09.086+0000 INFO  Sending metrics to CSV file at C:\Users\Eduardo\.Neo4jDesktop\neo4jDatabases\database-d61afe34-ba8a-4563-95ba-28a5c3fda71b\installation-4.0.1\metrics
2020-04-27 22:04:09.132+0000 INFO  Bolt enabled on localhost:7687.
2020-04-27 22:04:09.133+0000 INFO  Started.
2020-04-27 22:04:09.662+0000 INFO  Server thread metrics have been registered successfully
2020-04-27 22:04:11.557+0000 INFO  Remote interface available at http://localhost:7474/

Expected behavior

Running node index.js should result in:

{
  records: [],
  summary: ResultSummary {
    query: {
      text: 'CREATE (:Category {name: "verification" })',
      parameters: {}
    },
    queryType: 'w',
    counters: QueryStatistics { _stats: [Object], _systemUpdates: 0 },
    updateStatistics: QueryStatistics { _stats: [Object], _systemUpdates: 0 },
    plan: false,
    profile: false,
    notifications: [],
    server: ServerInfo { address: '0.0.0.0:7687', version: 'Neo4j/4.0.1' },
    resultConsumedAfter: Integer { low: 0, high: 0 },
    resultAvailableAfter: Integer { low: 174, high: 0 },
    database: { name: 'neo4j' }
  }
}

Actual behavior

Running node index.js should results in:

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

    at captureStacktrace (/mnt/c/Users/Eduardo/wsl/projects/test/node_modules/neo4j-driver/lib/result.js:263:15)
    at new Result (/mnt/c/Users/Eduardo/wsl/projects/test/node_modules/neo4j-driver/lib/result.js:68:19)
    at Session._run (/mnt/c/Users/Eduardo/wsl/projects/test/node_modules/neo4j-driver/lib/session.js:174:14)
    at Session.run (/mnt/c/Users/Eduardo/wsl/projects/test/node_modules/neo4j-driver/lib/session.js:135:19)
    at Object.<anonymous> (/mnt/c/Users/Eduardo/wsl/projects/test/test.js:5:18)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
  code: 'ServiceUnavailable',
  name: 'Neo4jError'
}

Workaround

Currently, I'm getting around this by running neo4j in a docker container.

I use the following to start up the docker container:

docker run -p 7474:7474 -p 7687:7687 --env NEO4J_AUTH=neo4j/root neo4j:4.0.1

This is the same version and username/password used in the Neo4j Desktop instance.

The only difference I can see is that it's running in docker.

The following is the log from starting up the docker instance:

Changed password for user 'neo4j'.
Directories in use:
  home:         /var/lib/neo4j
  config:       /var/lib/neo4j/conf
  logs:         /logs
  plugins:      /var/lib/neo4j/plugins
  import:       /var/lib/neo4j/import
  data:         /var/lib/neo4j/data
  certificates: /var/lib/neo4j/certificates
  run:          /var/lib/neo4j/run
Starting Neo4j.
2020-04-27 22:01:31.727+0000 INFO  ======== Neo4j 4.0.1 ========
2020-04-27 22:01:31.740+0000 INFO  Starting...
2020-04-27 22:01:39.771+0000 INFO  Bolt enabled on 0.0.0.0:7687.
2020-04-27 22:01:39.772+0000 INFO  Started.
2020-04-27 22:01:41.577+0000 INFO  Remote interface available at http://0.0.0.0:7474/

Has anyone else ran into this? Can you help point me in the right direction?

I intend to continue using the docker instance instead of Neo4j Desktop, I'm just curious as to what the difference is that's causing my issue.

MuddyBootsCode commented 4 years ago

I have the same issue. When using the latest version of the driver I cannot connect to my Aura instance at all. I get the same error.

zhenlineo commented 4 years ago

@es50678 You need to configured the advertised address to be something like 0.0.0.0. Your log already tells you. In the failed case, log contains 2020-04-27 22:04:09.132+0000 INFO Bolt enabled on localhost:7687.

While when using docker, log says 2020-04-27 22:01:39.771+0000 INFO Bolt enabled on 0.0.0.0:7687.

@MuddyBootsCode Try if you have the same, otherwise, be free to start your own issue.

MuddyBootsCode commented 4 years ago

@zhenlineo Will do. It's worth noting that this does not occur with version 1.7 of the driver. It's only when I upgraded that I began experiencing issues.

es50678 commented 4 years ago

@es50678 You need to configured the advertised address to be something like 0.0.0.0. Your log already tells you. In the failed case, log contains 2020-04-27 22:04:09.132+0000 INFO Bolt enabled on localhost:7687.

While when using docker, log says 2020-04-27 22:01:39.771+0000 INFO Bolt enabled on 0.0.0.0:7687.

I changed the following variables in the config file: dbms.default_advertised_address=0.0.0.0

I tried again and received the same error.

I tried with both const driver = neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'root')); and const driver = neo4j.driver('neo4j://0.0.0.0', neo4j.auth.basic('neo4j', 'root'));

Both result in the same error message:

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

    at captureStacktrace (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/result.js:263:15)
    at new Result (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/result.js:68:19)
    at Session._run (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/session.js:174:14)
    at Session.run (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/session.js:135:19)
    at Object.<anonymous> (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/index.js:5:18)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
  code: 'ServiceUnavailable',
  name: 'Neo4jError'
}

In addition, I also tried changing the following config variables in addition to the default advertised address:

dbms.connector.bolt.listen_address=:7687
dbms.connector.http.listen_address=:7474

@MuddyBootsCode did it work for you after changing the advertised address? Am I changing the wrong config variable?

oskarhane commented 4 years ago

The dbms.default_advertised_address should never be 0.0.0.0, it should be something that's reachable. I think the driver using neo4j:// scheme can't handle that when building it's routing table. If you try bolt:// instead of neo4j:// I suspect it works. But the real fix is to advertise something else, that's reachable.

The dbms.default_listen_address could be 0.0.0.0, if you want the dbms to accept connections from anywhere.

mikefontaine commented 4 years ago

I'm having the same issue using Neo4j desktop and bolt:://localhost:7687. This is happening with both JS and C#.NET. Everything worked fine until I upgraded to 1.1.21. I uninstalled and tried again on 1.2.8 and I have the same issue. I have confirmed that 7687 is not blocked and that the DB is running. I was able to connect using the REST interface in JS. I even disabled TLS in case that was a problem.

Was there a change in 1.1.21 that might account for this? It seems that the BOLT protocol just isn't working.

dbms.connector.bolt.enabled=true dbms.connector.bolt.tls_level=DISABLED

`# Bolt SSL configuration

dbms.ssl.policy.bolt.enabled=true

dbms.ssl.policy.bolt.base_directory=certificates/bolt

dbms.ssl.policy.bolt.private_key=private.key

dbms.ssl.policy.bolt.public_certificate=public.crt`

es50678 commented 4 years ago

@oskarhane

I changed:

I tried with the driver using neo4j://localhost and bolt://localhost.

Unfortunately, neither worked, I'm still receiving:

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

    at captureStacktrace (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/result.js:263:15)
    at new Result (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/result.js:68:19)
    at Session._run (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/session.js:174:14)
    at Session.run (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/node_modules/neo4j-driver/lib/session.js:135:19)
    at Object.<anonymous> (/mnt/c/Users/Eduardo/wsl/projects/freshit-api/index.js:5:18)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
  code: 'ServiceUnavailable',
  name: 'Neo4jError'
}

I'm sorry that it took me so long to reply. Thank you all again for helping me out with this ❤️

alete89 commented 4 years ago

experiencing the same.

running neo4j v4 with latest official docker image. On windows 10 host. using neo4j:// uri scheme, also tried with bolt:// with no success. both my docker-compose.yml looks like this:

neo4j:
    image: neo4j:4.0.4
    environment:
      - NEO4J_AUTH=neo4j/Password
      - NEO4J_dbms_connector_http_advertised__address=localhost:7474
      - NEO4J_dbms_connector_bolt_advertised__address=localhost:7687
    expose:
      - 7474
      - 7687
    ports:
      - 7474:7474
      - 7687:7687