Handle ServiceUnavailableException from the Java Bolt Driver
See original GitHub issueHi,
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:
- Created 7 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
Same issue here, trying to connect to an embedded instance with Bolt and java driver, any hint on how to do that?
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.