In Neo4j we currently have the configuration property referred to as execution guard:
that can be set automatically to kill transactions that take more than “x” seconds (x is equal to what is assigned to dbms.transaction.timeout, in this case 30s). However this is at global level and can’t be controlled for specific User or Query type.
So in order to implement this, a small script can be written and scheduled to run and kill the queries that take more than 30 seconds. This script can be triggered via cypher-shell. The query to kill the transaction that are not part of LOAD CSV and taking more than 30 seconds can be written as:
The query to kill the transaction where the user executing the query is not “neo4j” and taking more than 30 seconds:
You can modify the above query based on either certain parameters for queries or for certain users that should not be killed.
Note: This applies to Neo4j 3.1 and newer only!