Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Neo4j connections are growing and reach connection timeout

Hi. I'm working on a project which is using Neo4j Enterprise v. 4.2 .
I've stumbled upon problem, where under load connections number start to bloat, even if there is no need. They reach up to 100 connections and higher in the dbms connection list, while load remains approximately 2-4 requests per second. It looks like connections are either not being released, or are not reused.
In the application everything is built on the top of OGM v.3.2.15 with direct session management. Typical code is the next:


BoltDriver boltDriver =
        new BoltDriver(neo4jDriver) {
          public synchronized void close() {
boltDriver.configure(new Builder().database("dbName").build());
SessionFactory sessionFactory = new SessionFactory(ogmDriver);


    Transaction tx = null;
    try {
      Session session = sessionFactory.openSession();
      tx = session.beginTransaction(txType);
      Iterable<C> result = session.query(clazz, cypher, parameters);


      return result;
    } catch (Exception e) {
      if (tx != null) tx.rollback();
      throw e;

Similar procedure is used for most of the cases.

Recently I have added new operations based on pure Neo4j Driver v. with the next way of code running:

Config config = Config.builder()
        .withMaxTransactionRetryTime(5, TimeUnit.SECONDS)

Driver  driver = GraphDatabase.driver(neo4jUri, *some authorization*, config);

SessionConfig sc = SessionConfig.builder()


public List<Record> runQuery(ParamQuery query) {
    try (Session session = driver.session(sc)) {
      return, query.getParams()).list();

In some circumstances, usually after load on the OGM-based code, my pure Neo4j-based code freezes on transaction start and throws an error after a minute:

ServiceUnavailableException: Unable to connect to x.x.x.x(x.x.x.x):7687, ensure the database is running and that there is a working network connection to it.

Need your help in ideas what could it be and how to solve it. I'm currently out of ideas how to manage it.