Skip to content

apoc.periodic.iterate yields corrupted data #58

@michaelncy

Description

@michaelncy

Originally opened here: neo4j/apoc#823 (comment)

Expected Behavior

We're using an apoc.periodic.iterate query to delete relationships. Normally it yields all the output parameters correctly (for example updateStatistics is a map with the relevant fields).

Actual Behavior

We see where there's a deadlock in the query, the data that is yielded from the query (even though it succeeds after the deadlock) is corrupted, for example the updateStatistics is an int instead of a map.
We've also tried to run on our dev environment with yield only specific output parameters in order to avoid this issue, but we've still encountered the same problem, although seems like it's happening less frequently. Another error I saw on our dev env along side the original issue was: "ValueError('Invalid string length marker: 111')" originating from:

  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/work/result.py", line 605, in single
    await self._buffer(2)
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/work/result.py", line 443, in _buffer
    async for record in self:
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/work/result.py", line 393, in __aiter__
    await self._connection.fetch_message()
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/io/_common.py", line 195, in inner
    await coroutine_func(*args, **kwargs)
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/io/_bolt.py", line 991, in fetch_message
    tag, fields = await self.inbox.pop(
                  ^^^^^^^^^^^^^^^^^^^^^
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_async/io/_common.py", line 81, in pop
    self._unpacker.unpack(hydration_hooks) for _ in range(size)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/appuser/apps/test/.venv/lib/python3.12/site-packages/neo4j/_codec/packstream/v1/__init__.py", line 290, in unpack
    value, i = _rust_unpack(
               ^^^^^^^^^^^^^
ValueError: Invalid string length marker: 111

When using the regular neo4j driver the issue does not reproduce

How to Reproduce the Problem

Run an apoc.periodic.iterate query that deletes relationships with yielding all the output parameters.
In the same time run a query that creates relationships from one of the nodes in the first query to trigger a deadlock.

Simple Dataset

// First Query
CALL apoc.periodic.iterate("
    MATCH (:TEST)<-[r:REL]-(:BLA {a: $a}) RETURN id(r) AS id",
    "MATCH ()<-[r]-() WHERE id(r) = id DELETE r",
    {batchSize: 1000, parallel: false, retries: 5,  params: {a: $a}})

// Second Query - Pass a list of records to simulate a query that updates a batch of data
UNWIND $records AS record
MERGE (a:TEST)-[b:REL2]->(c:TEST2 {b: record})
ON CREATE SET a.test = "test"

Steps (Mandatory)

  1. Run both queries at the same time to ensure a deadlock happens using the python client
  2. Check the output from the first query

Screenshots (where it's possibile)

Image Image

Specifications

Currently used versions

Versions

  • OS: Neo4j Aura 2025.07
  • Neo4j-Apoc: 2025.07.1
  • Client: neo4j-python/5.26.0 Python-Rust/3.12.7-final-0 (linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions