Skip to content

Trigger is not called periodically because of closed transaction passed to setTriggerMetadataΒ #808

@dima-guzman

Description

@dima-guzman

Expected Behavior

A trigger is installed in the DB. It is expected it is reliable called each time a transaction has been committed that creates new nodes

Actual Behavior

Time to time when a series of queries is executed, the trigger execution code and in particular setTriggerMetadata mehtod receives a closed transaction, exception is thown and the trigger is not called

How to Reproduce the Problem

Intensively insert new nodes to the DB
The following example shows simultaneous insertion of some test nodes and relations. It is written is javascript, but any language that can send queries within transactions would allow to reporduce this

for (let i = 0; i < 15; i++) {
	setInterval(async () => {
		await runInTransaction(async (transaction) => {
			await transaction.run(
				`
WITH timestamp() as t
CREATE (r:Refund {id: "RF-1" + t + $i, isDeleted: false})
CREATE (r2:Refund {id: "RF-2" + t + $i, isDeleted: false})
CREATE (r3:Refund {id: "RF-3" + t + $i, isDeleted: false})
CREATE (r4:Refund {id: "RF-4" + t + $i, isDeleted: false})
CREATE (d:Document {id: "RI-1" + t + $i, isDeleted: false})
CREATE (d)-[:HAS_DOCUMENT]->(r)
CREATE (d)-[:HAS_DOCUMENT]->(r2)
CREATE (d)-[:HAS_DOCUMENT]->(r3)
CREATE (d)-[:HAS_DOCUMENT]->(r4)
				`,
				{ i }
			);
			console.info(`Thread ${i} insertion`);
		});
	}, 500);
}

There is also a trigger in the DB, the issue reproduces for both after and afterAsync stages

CALL apoc.trigger.install("${dbName}", "changeDetection", "
                ...
		RETURN 0
	", {phase: "afterAsync"})

Steps (Mandatory)

  1. Install a trigger to the DB
  2. Run Cypher queries creating nodes in parallel threads
  3. A crash happens with error message in the logs
2025-07-22 08:03:52.662+0000 ERROR id:14528408 - transaction id:411382 - 0 ms: (planning: 0, waiting: 0) - 312 B - 0 page hits, 0 page faults - embedded-session                core.prd -  - CALL tx.setMetaData($data) - {data: {apoc.trigger: true}} - runtime=pipelined - {}
org.neo4j.exceptions.CypherExecutionException: Failed to invoke procedure `tx.setMetaData`: Caused by: org.neo4j.graphdb.NotInTransactionException: The transaction has been closed.
        at org.neo4j.cypher.internal.planning.ExceptionTranslatingReadQueryContext.callDbmsProcedure(ExceptionTranslatingQueryContext.scala:357) ~[neo4j-cypher-5.26.8.jar:5.26.8]
        at org.neo4j.cypher.internal.runtime.DbmsCallMode$.callProcedure(ProcedureCallMode.scala:107) ~[neo4j-cypher-runtime-util-5.26.8.jar:5.26.8]
        at org.neo4j.codegen.OperatorTaskPipeline0_F9691E16_21569.compiledOperate(Unknown Source) ~[?:?]
        at org.neo4j.cypher.internal.runtime.pipelined.operators.CompiledTask.operateWithProfile(OperatorCodeGenBaseTemplates.scala:705) ~[neo4j-cypher-pipelined-runtime-5.26.8.jar:5.26.8]
        at org.neo4j.cypher.internal.runtime.pipelined.RegularPipelineTask.executeOperators(PipelineTask.scala:128) ~

Specifications (Mandatory)

Versions

  • OS: Windows 10, Ubuntu 22.04, Ubuntu 24.04
  • Neo4j: 5.26.8
  • Neo4j-Apoc: 5.26.8

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions