2

I've created a google cloud VM instance with neo4j on it, by following this instructions: https://neo4j.com/docs/operations-manual/current/cloud-deployments/neo4j-gcp/single-instance-vm/

The browser Db looks fine: I can view and manipulate from the browser.

The problem is when trying connecting neo4j from nodejs using neo4j-driver npm.

I keep getting this error:

UnhandledPromiseRejectionWarning: Neo4jError: Connection was closed by server

this is the code:

const neo4j = require('neo4j-driver')
const uri = 'bolt://[EXTERNAL_IP]:[PORT]'
const user = 'USER_NAME'
const password = 'PASSWORD'

const createPerson = async () => {
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), { encrypted : "ENCRYPTION_OFF"})
const session = driver.session()
const personName = 'Bob'
    try {
        const result = await session.run(
          'CREATE (a:Person {name: $name}) RETURN a',
          { name: personName }
        )

    const singleRecord = result.records[0]
    const node = singleRecord.get(0)

    console.log(node.properties.name)
  } finally {
    await session.close()
  }

  // on application exit:
  await driver.close()
}

createPerson()

The code is taken from this link: https://neo4j.com/developer/javascript/

I run this command: gcloud compute ssh my-neo4j-instance in GCP shell, in hope that maybe adding ssh would solve the issue but it didn't.

changing the driver encrypted options to false also didn't help.

Console logging the error print this:

Neo4jError: Connection was closed by server

at captureStacktrace (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:263:15)
at new Result (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:68:19)
at Session._run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:174:14)
at Session.run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:135:19)
at createPerson (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:12:38)
at Object.<anonymous> (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:31:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14) {


code: 'ServiceUnavailable',
  name: 'Neo4jError'

what am i missing ?

EDIT 1:

I looked the google cloud logs. all i saw was logs for the start and stop of the vm.

Also, i fixed the code for the async function call in the main file. so instead of the

 createPerson();

i tried this:

(async() => {
console.log('before start');

await createPerson();

console.log('after start');
})();

still no good, still: Neo4jError: Connection was closed by server. I also asked in neo4j blogs but got no answers.

EDIT 2:

I saw my issue in a different stack-overflow post. The answer there was to finish the logging to neo4j, by changing the password. but I already did that... Also I joined the neo4j slack group but didn't got an answer still.

Itay Tur
  • 683
  • 1
  • 15
  • 40
  • Did you check for firewall? Test encryption on? Correct auth? Bolt+routing? – Michael Hunger Jun 06 '20 at 15:20
  • @MichaelHunger for the firewall both http and https traffic are allowed. encryption is set to - Google managed, how can i test it ? i didn't set any auth and the uri i use is the one neo4j generated with the bolt protocol. full disclaimer it's my first time handling google cloud vm – Itay Tur Jun 06 '20 at 15:45
  • The http-server or https-server tags only allow traffic to ports 80 and 443 if your VM is in the [default network](https://cloud.google.com/vpc/docs/special-configurations). According to [this article](https://neo4j.com/docs/operations-manual/current/configuration/ports/) you might need particular ports opened (i.e. 7474, 7473) and you can created them as explained [here](https://cloud.google.com/vpc/docs/using-firewalls#creating_firewall_rules). You can also run a port scan like nmap to [check the status](https://nmap.org/book/man-port-scanning-basics.html) of your ports. – Carlos Jun 19 '20 at 21:23

0 Answers0