You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C Data stream import leaks the batch when the import fails before taking it from the array #1491
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:
Export a one-batch stream from a Java reader with Data.exportArrayStream.
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.
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
fix: release the Arrow stream when importing it runs out of memory