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. 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 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. So what could cause this connection to suddenly drop?