Skip to content

C Data stream import leaks the batch when the import fails before taking it from the array #1491

Open

Description

@sezruby

Describe the bug, including details regarding any error messages, version, and platform.

ArrowArrayStreamReader.loadNextBatch gets the next batch into an ArrowArray and imports it with Data.importIntoVectorSchemaRoot(allocator, array, getVectorSchemaRoot(), provider). Before the import moves the batch out of the array, it allocates up to two structs from the reader's allocator:

  • the schema struct, on the first batch if the schema has not been read yet (readSchema);
  • the struct the batch moves into (ArrayImporter.importArray).

If either allocation fails, the batch is still in the array. That happens when the allocator is at its limit, or when its AllocationListener throws. The try-with-resources in loadNextBatch then closes the struct without calling its release callback, so the producer's batch is never released.

This is the stream counterpart of #1239, which fixed the same leak for failures while importing the buffers.

Reproduction:

  1. Export a one-batch stream from a Java reader with Data.exportArrayStream.
  2. Import it with Data.importArrayStream into a child allocator whose limit admits the stream and array structs but not the next struct: 192 bytes with the current struct sizes.
  3. loadNextBatch throws OutOfMemoryException. After the reader is closed, the exporting allocator still holds the batch: 16688 bytes for 1024 short strings.

The same failure happens whether the schema is read lazily (the schema struct fails) or before the first batch (the struct the batch moves into fails).

Expected: the batch is released when loadNextBatch fails, as it is when the import fails later, while importing a buffer.

Seen on main (c0fb78e). The same code is in 15.0.0 and 18.3.0. Platform-independent; reproduced on macOS aarch64 with JDK 17.

We hit it with an allocator whose AllocationListener reserves memory from a query engine's memory manager and throws when none is left.

Activity

  1. added this to the 20.0.0 milestone on Nov 17, 2026
  2. removed this from the 20.0.0 milestone on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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