[
https://issues.apache.org/jira/browse/TINKERPOP-2719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508130#comment-17508130
]
ASF GitHub Bot commented on TINKERPOP-2719:
-------------------------------------------
FlorianHockmann commented on a change in pull request #1586:
URL: https://github.com/apache/tinkerpop/pull/1586#discussion_r828987815
##########
File path:
gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
##########
@@ -383,9 +383,14 @@ protected void handleIterator(final Context context, final
Iterator itty, final
break;
}
+ // track whether there is anything left in the iterator
because it needs to be accessed after
+ // the transaction could be closed - in that case a call
to hasNext() could open a new transaction
+ // unintentionally
+ final boolean moreInIterator = itty.hasNext();
Review comment:
`hasMore` is only set to `false` in line 401 and that is in the `else`
block of the if condition: `if (moreInIterator)`. So if we also use `hasMore`
here instead, then `hasMore` cannot become `false` any more.
This additional `itty.hasNext()` is needed here to check whether more
elements are available after the last `next()`. This is also explained in the
comment above starting at line 337:
```
// there is a need to check hasNext() on the iterator because if
the channel is not writeable the
// previous pass through the while loop will have next()'d the
iterator and if it is "done" then a
// NoSuchElementException will raise its head. also need a check
to ensure that this iteration doesn't
// require a forced flush which can be forced by sub-classes.
```
This is also in line with the implementation in `AbstractOpProcessor` where
it's implemented exactly like this. We really just copied the logic from there.
--
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]
> hasNext is called on TraverserIterator after transaction is committed
> ---------------------------------------------------------------------
>
> Key: TINKERPOP-2719
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2719
> Project: TinkerPop
> Issue Type: Bug
> Components: server
> Affects Versions: 3.5.2
> Reporter: Florian G
> Priority: Major
>
> In {{{}TraversalOpProcessor{}}}, the {{hasNext()}} [function is
> called|https://github.com/apache/tinkerpop/blob/a52887d084053cd420580a0c0a80e745b49ee252/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java#L428]
> on a {{TraversalIterator}} object after the transaction [is
> committed|https://github.com/apache/tinkerpop/blob/a52887d084053cd420580a0c0a80e745b49ee252/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java#L414].
> This causes issues if the database tries to further execute the traversal
> upon the {{hasNext()}} call but has no access to the transaction anymore.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)