imbajin commented on code in PR #3167:
URL: https://github.com/apache/hugegraph/pull/3167#discussion_r3845557682


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/ShortestPathTraverser.java:
##########
@@ -184,33 +184,40 @@ public PathSet forward(boolean all) {
             while (this.pathResults.hasNextKey()) {
                 Id source = this.pathResults.nextKey();
 
-                Iterator<Edge> edges = edgesOfVertex(source, this.direction,
-                                                     this.labels, degree);
-                edges = skipSuperNodeIfNeeded(edges, this.degree,
-                                              this.skipDegree);
-
-                this.vertexCount += 1L;
-
-                while (edges.hasNext()) {
-                    HugeEdge edge = (HugeEdge) edges.next();
-                    Id target = edge.id().otherVertexId();
-
-                    this.edgeResults.addEdge(source, target, edge);
-
-                    PathSet paths = this.pathResults.findPath(target,
-                                                              t -> 
!this.superNode(t,
-                                                                               
    this.direction),
-                                                              all, false);
-
-                    if (paths.isEmpty()) {
-                        continue;
-                    }
-                    results.addAll(paths);
-                    if (!all) {
-                        return paths;
+                Iterator<Edge> sourceEdges = edgesOfVertex(
+                        source, this.direction, this.labels, degree);
+                Throwable failure = null;
+                try {
+                    Iterator<Edge> edges = skipSuperNodeIfNeeded(
+                            sourceEdges, this.degree, this.skipDegree);
+
+                    this.vertexCount += 1L;
+
+                    while (edges.hasNext()) {
+                        HugeEdge edge = (HugeEdge) edges.next();
+                        Id target = edge.id().otherVertexId();
+
+                        this.edgeResults.addEdge(source, target, edge);
+
+                        PathSet paths = this.pathResults.findPath(
+                                target,
+                                t -> !this.superNode(t, this.direction),
+                                all, false);
+
+                        if (paths.isEmpty()) {
+                            continue;
+                        }
+                        results.addAll(paths);
+                        if (!all) {
+                            return paths;
+                        }
                     }
+                } catch (RuntimeException | Error e) {
+                    failure = e;
+                    throw e;
+                } finally {
+                    closeIterator(sourceEdges, failure);

Review Comment:
   ⚠️ Important
   
   Blocking: yes. When a finite multi-label iterator reaches its limit, 
`LimitIterator.fetch()` already closes the wrapped `ExtendableIterator`. This 
`finally` block then closes the same wrapper again, and 
`ExtendableIterator.close()` retains its children without a closed guard, so 
the current backend iterator receives a second `close()` call.
   
   `AutoCloseable` does not require idempotent close semantics, so the second 
call can trigger duplicate remote cleanup or turn an otherwise successful 
traversal into a cleanup failure. Please make the wrapper/origin close path 
idempotent and add a regression asserting that every child is closed exactly 
once.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to