Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket hang-up using neo4j JS driver

all. I'm new to neo4j and trying to use the official JS driver from node / express to hit a remote (e.g. non-local) server, but keep getting [Error: socket hang up] code: 'ECONNRESET' errors. Code looks like this:

router.get('/', function(req, res, next) {
  var driver  = neo4j.driver("bolt://ip.address", neo4j.auth.basic("neo4j", "neo4j"));
  var session = driver.session();
  var query   = "MATCH (p:Person {name:'Sally'})-[r:KNOWS]->(f:Person) RETURN f";

  session
    .run(query)
    .then(function(result) {
      result.records.forEach(function(record) {
        console.log(record._fields);
      });
      session.close();
    })
    .catch(function(error) {
      console.log(error);
    });

  driver.close();
});

I've tried both the streaming and promise techniques on both bolt and http, all with the same outcome. Remote server is config'ed to accept external connections and I've verified connectivity separately via golang.

Ideas?

like image 938
Ray Bradley Avatar asked Dec 05 '22 16:12

Ray Bradley


1 Answers

Thanks to Oscar Hane for answering this over on Github:

Your issue is that you're potentially closing the driver before your query are finished.

router.get('/', function(req, res, next) {
  var driver  = neo4j.driver("bolt://ip.address", neo4j.auth.basic("neo4j", "neo4j"));
  var session = driver.session();
  var query   = "MATCH (p:Person {name:'Sally'})-[r:KNOWS]->(f:Person) RETURN f";

  session
    .run(query)
    .then(function(result) {
      result.records.forEach(function(record) {
        console.log(record._fields);
      });
      session.close();
      driver.close();
    })
    .catch(function(error) {
      console.log(error);
      driver.close();
    });
});
like image 132
Ray Bradley Avatar answered Dec 30 '22 11:12

Ray Bradley