Search code examples
neo4jgraph-databasesneo4jclientnosql

Neo4j 500 Internal Server Error on concurrent writes


I'm experiencing 500 Internal Server Error occasionally when performing concurrent writes to Neo4j. Query example below.

MATCH (u1:User {id:{id1}})
MATCH (u2:User {id:{id2}})
MERGE (u1)-[:FOLLOWS]->(u2)

In case of very popular user you can experience high number of concurrent relationship creations for the u2 node.

At the momement I'm explicitly handling DeadlockDetectedException and have a retry logic in place. But from time to time I'm getting 500 from the server with response body below.

 <html>
     <head><title>500 Internal Server Error</title></head>
     <body bgcolor="white">
         <center><h1>500 Internal Server Error</h1></center>
         <hr><center>nginx</center>
      </body>
 </html>

Which gives me no clue what happened on the server. If I handle it and perform a retry everything works as expected. But this looks pretty dodgy as I basically guessing that in this particular case deadlock happened which might be wrong and unrelated to the actual server error.


Solution

  • This issue was related to our ngnix box configuration which gave generic 500 in some occasions instead of propagating DeadlockDetectedException.