vaidikgarg-bit opened a new issue, #3436:
URL: https://github.com/apache/hugegraph/issues/3436
### Bug Type (问题类型)
logic (逻辑设计问题)
### Environment (环境信息)
- Server Version: `master` at `29333a6ec` (1.8.0-SNAPSHOT)
- Backend: HStore (`hg-store-core` `MultiListIterator`)
- JDK 17
### Expected & Actual behavior (期望与实际表现)
Closing a `MultiListIterator` should close every sub-iterator it holds. If
`close()` is called before the first `hasNext()`, none of them are closed.
`close()` only closes `innerIterator` and whatever is left in
`innerListIterator`:
```java
if (this.innerIterator != null) {
this.innerIterator.close();
}
if (this.innerListIterator != null) {
while (this.innerListIterator.hasNext()) {
this.innerListIterator.next().close();
}
}
this.iterators.clear();
```
Both fields are set lazily in `getInnerIterator()`, which runs on the first
`hasNext()` or `isValid()` call. Before that they are `null`, so `close()`
skips both blocks and then clears the list. The sub-iterators are never closed
and can't be reached anymore.
`BusinessHandlerImpl` builds the sub-iterators up front (`scan`,
`scanPrefix`, `indexIntersection`, `BatchGetIterator`), then wraps them in a
`MultiListIterator` for multi-param scans and multi-index queries, often inside
a dedup wrapper whose `close()` just calls through. One path that closes it
before iterating is `AggregativeQueryObserver`: it creates the iterator, and if
the client cancels before the read loop runs `while (!this.clientCanceled.get()
&& this.iterator.hasNext())`, it exits without ever calling `hasNext()`. The
task then calls `iterator.close()`, and the store-side scan iterators stay open.
Reproduction (in `FilterIteratorContractTest`):
```java
RowIterator first = new RowIterator(List.of(BackendColumn.of(new byte[]{1},
new byte[]{11})));
RowIterator second = new RowIterator(List.of(BackendColumn.of(new byte[]{2},
new byte[]{12})));
MultiListIterator iterator = new MultiListIterator(List.of(first, second));
iterator.close();
assertTrue(first.closed); // fails on master
assertTrue(second.closed);
```
It fails the same way when wrapped in `MapLimitIterator`.
I'd like to work on this: when `close()` runs before iteration starts, close
every sub-iterator in the list. Sub-iterators that were already exhausted and
closed during iteration would not be closed a second time.
--
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]