Closed mcpat1993 closed 6 years ago
Hi @mcpat1993,
I think there is a problem in the #initGraph()
function. Call Session#run()
is async and thus returns a promise. However, the driver instance is closed outside of the promise so it might get executed before query completes. Please see the following snippet:
...
var driver = neo4j.v1.driver("bolt://172.24.84.139:7687", neo4j.v1.auth.basic("", ""));
var session = driver.session();
session
.run('MATCH (p1:Object{name:"xt3lab-fabric05"}), (p2:Object), path = ((p1)-[*..5]-(p2)) RETURN path ORDER BY LENGTH(path) DESC')
.then(function (result) {
var nodes = [], rels = [], i = 0
result.records.forEach(function (record) {
nodes.push({name: record._fields[0].end.properties.name});
graph.addLink('xt3lab-fabric05', nodes[i].name);
i = i+1;
});
session.close();
driver.close(); // <<-- close driver after the whole result is consumed
})
.catch(function (error) {
console.log(error);
});
...
Hope this helps, please update this issue with the outcome.
Thanks for the quick reply, but I have added the driver.close function in the then portion of the session but I'm getting the same error. In the README file usage examples it also does not include driver.close()
@mcpat1993 readme does mention that lifecycle of the driver needs to be explicitly managed by the application. It is not required to open/close driver per query. Recommended approach is to keep single driver per application/webpage and close it explicitly on shutdown. Relevant docs section is here.
I can only reproduce seen error when driver.close()
is outside of the promise. Here is my simple code:
<script src="https://rawgit.com/neo4j/neo4j-javascript-driver/1.4/lib/browser/neo4j-web.js"></script>
<script>
var driver = neo4j.v1.driver("bolt://localhost", neo4j.v1.auth.basic("", ""))
var session = driver.session()
session.run("return 42")
.then(function(result){ console.log("SUCCESS: " + result.records[0].get(0)) })
.catch(function(error){ console.log("ERROR: ", error) })
//.then(function(){ driver.close() }) // <<-- uncomment this line to fix the error
driver.close() // <<-- comment this line to fix the error
</script>
Error:
WebSocket connection to 'ws://localhost:7687/' failed: WebSocket is closed before the connection is established.
and it never shows up when driver.close()
is part of the promise chain.
Did you remove previous driver.close()
? There should remain only a single one inside the promise chain.
@lutovich I think I understand what you mean. I appreciate the advice with the final .then clause of the session variable. I ended up using that. I'm ashamed at what I discovered to be my actual problem though. While my drivers URI was valid, it wasn't where my Neo4j DB was located. I must have just mistyped as it should have been 172.24.84.130 and not .139. I still think it's bizarre that I was getting that error and not a connection refused error or something like that. What a disgraceful error. Sorry to bother you, but thanks for your help.
Hello,
I'm running an Apache2 Webserver and including the driver in my index.html file as well as my Javascript that runs the queries to the Neo4j database that I have. My file heirarchy is as follows: