You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2021/11/19 15:43:42 UTC

[tinkerpop] 01/01: TINKERPOP-2626 Prevent premature close of traversal

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2626
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 96ccc21a8dc3134c4a5148bf1ada855ec7a79a4e
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Fri Nov 19 10:40:22 2021 -0500

    TINKERPOP-2626 Prevent premature close of traversal
    
    This is not a complete fix for this issue but does get rid of the premature close. Opted to try to close the Traversal as part of hasNext() as in a sense it is a way to complete iteration of the traversal. Without that change certain tests begin to fail so some additional change besides removing the premature close had to be added.
---
 CHANGELOG.asciidoc                                                    | 1 +
 .../gremlin/process/traversal/step/filter/RangeGlobalStep.java        | 3 ---
 .../tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java    | 4 +++-
 .../apache/tinkerpop/gremlin/structure/util/CloseableIterator.java    | 3 +--
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index cd8fdf0..d4912d1 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-4-13]]
 === TinkerPop 3.4.13 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Fixed `RangeGlobalStep` which was prematurely closing the iterator.
 * Prevented XML External Entity (XXE) style attacks via `GraphMLReader` by disabling DTD and external entities by default.
 * Improved error message for failed serialization for HTTP-based requests.
 * Fixed a `NullPointerException` that could occur during a failed `Connection` initialization due to uninstantiated `AtomicInteger`.
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
index 37441eb..9824332 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
@@ -63,9 +63,6 @@ public final class RangeGlobalStep<S> extends FilterStep<S> implements Ranging,
         if (this.bypass) return true;
 
         if (this.high != -1 && this.counter.get() >= this.high) {
-            // This is a global step and this place would be the end of the traversal.
-            // Close the traversal to free up resources.
-            CloseableIterator.closeIterator(traversal);
             throw FastNoSuchElementException.instance();
         }
 
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index cd3b7c4..3aa7bc1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -193,7 +193,9 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
     @Override
     public boolean hasNext() {
         if (!this.locked) this.applyStrategies();
-        return this.lastTraverser.bulk() > 0L || this.finalEndStep.hasNext();
+        final boolean more = this.lastTraverser.bulk() > 0L || this.finalEndStep.hasNext();
+        if (!more) CloseableIterator.closeIterator(this);
+        return more;
     }
 
     @Override
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/CloseableIterator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/CloseableIterator.java
index 2464d11..5c33f8d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/CloseableIterator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/CloseableIterator.java
@@ -51,8 +51,7 @@ public interface CloseableIterator<T> extends Iterator<T>, Closeable {
         if (iterator instanceof AutoCloseable) {
             try {
                 ((AutoCloseable) iterator).close();
-            }
-            catch (Exception e) {
+            } catch (Exception e) {
                 throw new RuntimeException(e);
             }
         }