cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

ECONNREFUSED on Mac only

I'm running a neo4j database as well as an node.js api in a Docker container. On startup, the api tries to import a lot of data into neo4j, accessing it through neo4-driver. I can also run those imports manually from inside the Docker container or outside (locally).

This used to work fine. It works fine on Windows, it works fine for other people using a Macbook, and sometimes it also works for me, but then the connection mysteriously drops and I only get ECONNREFUSED errors anymore, until I restart the container. And sometimes it just doesn't work at all. Neither neo4j nor Docker give any indication that anything is wrong. Nothing in the logs, they don't seem to have crashed, they're just inaccessible. The neo4j browser interface on port 7474 is also gone, though it used to be there.

The fact that this sometimes works is the baffling part. But it never works for long, before I get the errors again. When it drops, I often (not always) first get an EPIPE error.

I used to run Docker/docker desktop 3.1 and 10.20.2, now upgraded to 3.6.0 and 10.20.8. Neo4j version 3. The api runs on Alpine.

I use docker-compose -p 7687:7687 -f ./docker-compose.yml up to start Docker, and my docker-compose.yml file looks like this:

version: '3'

services:
  neo4j:
    build:
      context: ./db/
    ports:
      - "7474:7474"
      - "7687:7687"

  api:
    build:
      context: ./api/
    volumes:
      - ./api/:/code/
    depends_on:
      - neo4j
    ports:
      - "3000:3000"

I execute queries to neo4j through neo4j-driver with:

const session = driver.session();
session.writeTransaction((tx) => tx.run(query, params))

where driver was previously initialized with

const driver = neo4j.driver(neo4jUrl, neo4j.auth.basic(user, passwd), {});

The most common error is this:

Neo4jError: connect ECONNREFUSED 172.20.0.2:7687

  at captureStacktrace (/code/node_modules/neo4j-driver/lib/v1/result.js:199:15)
  at new Result (/code/node_modules/neo4j-driver/lib/v1/result.js:65:19)
  at _newRunResult (/code/node_modules/neo4j-driver/lib/v1/transaction.js:354:10)
  at Object.run (/code/node_modules/neo4j-driver/lib/v1/transaction.js:238:14)
  at Transaction.run (/code/node_modules/neo4j-driver/lib/v1/transaction.js:104:26)
  ...
  at TransactionExecutor._safeExecuteTransactionWork (/code/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:134:22)
  at TransactionExecutor._executeTransactionInsidePromise (/code/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:122:32)
  at Timeout._onTimeout (/code/node_modules/neo4j-driver/lib/v1/internal/transaction-executor.js:98:18)
  at listOnTimeout (internal/timers.js:557:17) {
code: 'ServiceUnavailable'

I suspect it might have something to do with Docker differences between Windows and Mac, but I'm not sure. It has also worked fine with other Mac users, and occasionally does work for me, just not for long. And sometimes I just can't get it working at all. But the reason for that completely eludes me.

Any idea what could cause this?

2 REPLIES 2

andreperez
Graph Buddy

Are you declaring an initial password?

The latter states the following:

By default, Neo4j requires authentication and requires us to first login with neo4j/neo4j and set a new password. We will skip this password reset by initializing the password when we create the Docker container using the --env NEO4J_AUTH=neo4j/<password> option.

As far as I know, yes we set a password from the Dockerfile for neo4j. I hadn't posted that yet, so here it is:

FROM neo4j:3.5-enterprise

USER neo4j

ENV NEO4J_dbms_memory_heap_max__size=2G
ENV NEO4J_dbms_memory_pagecache_size=2G

EXPOSE 7474 7687 6362

CMD rm -f /var/lib/neo4j/data/dbms/auth && \
  bin/neo4j-admin set-initial-password fakepasswd && \
  bin/neo4j start && \
  tail -f logs/neo4j.log

Is this something that could explain occasionally allowing a connection and later blocking it?