vaidikgarg-bit opened a new issue, #3444:
URL: https://github.com/apache/hugegraph/issues/3444

   ### Bug Type (问题类型)
   
   logic (逻辑设计问题)
   
   ### Before submit
   
   - [x] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 
[FAQ](https://hugegraph.apache.org/docs/guides/faq/) 中没有相同 / 重复问题 (I have 
confirmed and searched that there are no similar problems in the historical 
issue and documents)
   
   ### Environment (环境信息)
   
   - Server Version: `master` at `8e327b8f3` (1.8.0)
   - Backend: HStore (`hg-store-core` `MultiListIterator`)
   - JDK 17
   - OS / Data Size: N/A (reproduced in a unit test)
   
   ### Expected & Actual behavior (期望与实际表现)
   
   #3437 fixed `MultiListIterator.close()` when it is called before the first 
`hasNext()`. Three related problems are still in the class:
   
   1. A failing sub-iterator close leaks the rest. `close()` closes the current 
sub-iterator and then the remaining ones in a plain loop, with no 
`try`/`finally`. If one of those calls throws, the later sub-iterators stay 
open and `iterators.clear()` never runs. This happens before iteration starts 
and also partway through it, when the sub-iterator currently being read is the 
one that fails. Close failures do happen: `RocksDBScanIterator.close()` 
rethrows failures from the native iterator close, its close callback and the 
reference release. `UnionFilterIterator` and `IntersectionFilterIterator` in 
the same package use `try`/`finally` so their cleanup still runs.
   
   2. `next()` without `hasNext()` is broken. `innerIterator` is only set 
inside `hasNext()`/`isValid()`, so calling `next()` first, or after `hasNext()` 
has returned `false`, throws `NullPointerException` where the 
`java.util.Iterator` contract, which `ScanIterator` mirrors and 
`RocksDBScanIterator.next()` follows, expects the next element or 
`NoSuchElementException`. After one `hasNext()`, calling `next()` repeatedly 
never moves on to the next sub-iterator: once the current one is drained, 
`next()` keeps calling it and gets `NoSuchElementException`, even though later 
sub-iterators still have rows.
   
   3. A closed iterator keeps touching its sources. `close()` leaves 
`innerIterator` set. The first `hasNext()` or `isValid()` after `close()` calls 
`innerIterator.hasNext()` on the closed source. If that returns `false`, it 
closes the source a second time, and `isValid()` then returns `true`. 
`RocksDBScanIterator` returns `false` from `hasNext()` once closed and does not 
repeat the native close, but a `ScanIterator` without such a guard is used 
after it was closed.
   
   Reproduction (in `FilterIteratorContractTest`, using its `RowIterator` and 
`singleRow` helpers):
   
   ```java
   // 1, before iteration: second and third are never closed
   RowIterator first = singleRow(1), second = singleRow(2), third = 
singleRow(3);
   first.closeFailure = new IllegalStateException("close failed");
   MultiListIterator before = new MultiListIterator(List.of(first, second, 
third));
   assertThrows(IllegalStateException.class, before::close);
   assertEquals(1, second.closes); // fails, was 0
   
   // 1, during iteration: the source being read fails to close, the next one 
is never closed
   RowIterator r1 = singleRow(1), r2 = singleRow(2);
   r1.closeFailure = new IllegalStateException("close failed");
   MultiListIterator mid = new MultiListIterator(List.of(r1, r2));
   mid.hasNext();
   assertThrows(IllegalStateException.class, mid::close);
   assertEquals(1, r2.closes); // fails, was 0
   
   // 2
   new MultiListIterator(List.of(singleRow(1))).next(); // NullPointerException
   
   MultiListIterator two = new MultiListIterator(List.of(singleRow(1), 
singleRow(2)));
   two.hasNext();
   two.next(); // row 1
   two.next(); // NoSuchElementException from the drained first source; row 2 
is never returned
   
   // 3
   RowIterator a = singleRow(1);
   MultiListIterator it = new MultiListIterator(List.of(a, singleRow(2)));
   it.hasNext();
   it.close();
   it.hasNext();
   assertEquals(1, a.closes); // fails, was 2
   ```
   
   Expected:
   
   1. `close()` closes every sub-iterator, clears the list, and then rethrows 
the first failure with any later ones attached as suppressed.
   2. `next()` returns the next element when there is one, moving on to the 
next sub-iterator as needed, and throws `NoSuchElementException` otherwise.
   3. After `close()`, `hasNext()` and `isValid()` return `false` without 
calling any source, and a second `close()` does nothing.
   
   ### Vertex/Edge example (问题点 / 边数据举例)
   
   N/A
   
   ### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
   
   N/A
   


-- 
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