sezruby opened a new issue, #1491:
URL: https://github.com/apache/arrow-java/issues/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:**
   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 (c0fb78e8). 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to