Unhandled ExclusiveLock Exception in Node.js with Neo4j 5.26.1 – Unable to Catch the Error

Hi everyone,

I’m running a highly concurrent application that writes multiple nodes and relationships into Neo4j Enterprise Edition 5.26.1 using the official Neo4j Node.js driver 5.26. The entire application is wrapped in a try/catch block, and I am awaiting all Neo4j write operations.

Whenever I encounter Neo4j errors like Timeouts or Insufficient Memory, I can catch them and handle retries accordingly. However, when a ** ExclusiveLock Exception** occurs, I cannot catch it in my try/catch block. The only way I can detect it is through the unhandledRejection event in Node.js:

Unhandled Promise Rejection at: [object Promise], Reason:Neo4jError: ForsetiClient[transactionId=15157613, clientId=2396215] can't acquire ExclusiveLock{owner=ForsetiClient[transactionId=15157626, clientId=2396214]} on NODE(670236072) because holders of that lock are waiting for ForsetiClient[transactionId=15157613, clientId=2396215].
Wait list:ExclusiveLock[
Client[15157626] waits for [ForsetiClient[transactionId=15157613, clientId=2396215]]], Stack trace: Neo4jError: ForsetiClient[transactionId=15157613, clientId=2396215] can't acquire ExclusiveLock{owner=ForsetiClient[transactionId=15157626, clientId=2396214]} on NODE(670236072) because holders of that lock are waiting for ForsetiClient[transactionId=15157613, clientId=2396215].
Wait list:ExclusiveLock[
Client[15157626] waits for [ForsetiClient[transactionId=15157613, clientId=2396215]]]

at captureStacktrace (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/result.js:624:17)
at new Result (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/result.js:112:23)
at finishTransaction (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/transaction.js:510:12)
at Object.commit (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/transaction.js:323:25)
at Transaction.commit (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/transaction.js:204:37)
at TransactionExecutor._handleTransactionWorkSuccess (/usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:225:16)
at /usr/src/app/node_modules/.pnpm/neo4j-driver-core@5.26.0/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:201:42
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Has anyone faced this issue before ?

Hello @nadavbi87!

I am maintaining the Neo4j JS driver. I will be looking into your issue to see if there's something irregular being done with error handling for lock exceptions.

In the meantime, since I assume you are using session.run() for your queries, you can let driver itself to handle retry logic for retryable errors by using the driver.executeQuery() or session.executeRead()/executeWrite() methods.