question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle ServiceUnavailableException from the Java Bolt Driver

See original GitHub issue

Hi,

As per https://github.com/neo4j/neo4j-java-driver/issues/302, the Java Driver is launching ServiceUnavailableException in case the client loses connection with the server (eg. network glitches, server restarts, …). AFAIK the philosophy is that the libs and apps using the driver should catch ServiceUnavailableException.

However, I noticed that neo4j-ogm does not handle ServiceUnavailableException yet. The only reference to a server disconnection I’ve found is ClientException being rethrown as a CypherException:

It seems that CypherException is too generic. For instance, spring-data-neo4j handles it this way:

org.springframework.data.neo4j.exception.UncategorizedNeo4jException: Error executing Cypher; 
  Code: N/A; Description: SSL Connection terminated while receiving data. 
  This can happen due to network instabilities, or due to restarts of the database.; 

nested exception is org.neo4j.ogm.exception.CypherException: Error executing Cypher; 
  Code: N/A; Description: SSL Connection terminated while receiving data. 
  This can happen due to network instabilities, or due to restarts of the database.

So they don’t have the information that a ServiceUnavailableException conveys, which for spring-data-neo4j could mean converting it to a RecoverableDataAccessException so that the connection could be retried (see: https://github.com/spring-projects/spring-data-neo4j/issues/373)

In my (maybe naïve) debugging session, I’ve found that a possible solution could be creating a org.neo4j.ogm.exception.ServiceCommunicationException that can be used by the upper layers (eg. spring-data-neo4j). But where should the exception be launched?

Well, it seems that both BoltRequest.java and BoltResponse.java don’t check for stale sessions:

transactionManager.getCurrentTransaction() == null

Wouldn’t be enough, since the connection is stalled (hence not null) and the failure happens only after the request is executed or the results are fetched.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
nsteenvcommented, May 2, 2017

Same issue here, trying to connect to an embedded instance with Bolt and java driver, any hint on how to do that?

0reactions
michael-simonscommented, Dec 5, 2018

Thanks for your feedback.

The Bolt transport will now translate this into org.neo4j.ogm.exception.ConnectionException. We plan on further refining in this area as well.

Regarding running embedded and opening a bolt port to the outside: We strongly recommend not doing this. Neo4j-OGM uses the database api to communicate with the embedded instance, too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java driver issue - Neo4j - 15104
ServiceUnavailableException : Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the ...
Read more >
org.neo4j.driver.v1.exceptions.ServiceUnavailableException ...
private static Throwable databaseUnavailableError( BoltServerAddress address, Throwable cause ) { return new ServiceUnavailableException( format( "Unable to ...
Read more >
Neo4J bolt connector not working - Stack Overflow
ServiceUnavailableException : Unable to connect to localhost:7687, ... <init>(SocketConnection.java:67) at org.neo4j.driver.internal.net.
Read more >
neo4jrb/neo4j - Gitter
@klobuczek , I'm trying to use the neo4j-java-driver gem and it shows up, ... Is there a better way to handle this while...
Read more >
The Neo4j Drivers Manual V1.7 For Java driver 1.7
A routing driver is created via a bolt+routing URI, for example: ... Ê catch ( ServiceUnavailableException ex ). Ê {. Ê return false;....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found