You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by xi...@apache.org on 2023/02/22 01:03:11 UTC

[tinkerpop] branch 3.5-dev updated: Fix server not handling StackOverflowError in bytecode traversals (#1946)

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

xiazcy pushed a commit to branch 3.5-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.5-dev by this push:
     new 3c9731f374 Fix server not handling StackOverflowError in bytecode traversals (#1946)
3c9731f374 is described below

commit 3c9731f3745520fbcca536b83ca404095546fa15
Author: Cole Greer <11...@users.noreply.github.com>
AuthorDate: Tue Feb 21 17:03:03 2023 -0800

    Fix server not handling StackOverflowError in bytecode traversals (#1946)
    
    Fixes TINKERPOP-2767.
    
    The existing error handling in TraversalOpProcessor and SessionOpProcessor during bytecode iteration was
    catching all exceptions sending an appropriate error response to the client. The OpProcessor however was
    not catching a StackOverflowError which could be induced by running a query which contains a
    large repeat step. This Error was being caught by FutureTask.run() but GremlinServer never wait's
    on this task or checks the results which caused this Error to be lost.
    A similar issue was found to exist in AbstractSession.process().
    
    This commit adjusts the existing error handling code to catch any Throwable during bytecode
    iteration so clients will receive error messages and codes for server errors as well as exceptions.
    Any errors are re-thrown such that the evalFuture FutureTask will continue to have an exception set
    correctly (although GremlinServer currently does not use this for anything).
---
 CHANGELOG.asciidoc                                 |  1 +
 .../gremlin/server/handler/AbstractSession.java    |  4 +--
 .../server/op/session/SessionOpProcessor.java      | 32 ++++++++++++++--------
 .../server/op/traversal/TraversalOpProcessor.java  | 16 +++++++----
 4 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 7a14f6aa8b..51b661c90d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Changed `PartitionStrategy` to force its filters to the end of the chain for `Vertex` and `Edge` read steps, thus preserving order of the `has()`.
 * Added `RequestOptions` and `RequestOptionsBuilder` types to Go GLV to encapsulate per-request settings and bindings.
 * Added `SubmitWithOptions()` methods to `Client` and `DriverRemoteConnection` in Go GLV to pass `RequestOptions` to the server.
+* Fixed bug in which `gremlin-server` would not respond to clients if an `Error` was thrown during bytecode traversals.
 
 [[release-3-5-5]]
 === TinkerPop 3.5.5 (Release Date: January 16, 2023)
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/AbstractSession.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/AbstractSession.java
index 02405d2c21..e38c069c9c 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/AbstractSession.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/AbstractSession.java
@@ -280,8 +280,8 @@ public abstract class AbstractSession implements Session, AutoCloseable {
 
             if (itty.isPresent())
                 handleIterator(sessionTask, itty.get());
-        } catch (Exception ex) {
-            handleException(sessionTask, ex);
+        } catch (Throwable t) {
+            handleException(sessionTask, t);
         } finally {
             timer.stop();
         }
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
index 6216835ff8..4077ffdb11 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
@@ -446,19 +446,23 @@ public class SessionOpProcessor extends AbstractEvalOpProcessor {
                     }
                     onError(graph, context);
                 }
-            } catch (Exception ex) {
-                final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(ex);
+            } catch (Throwable t) {
+                onError(graph, context);
+                final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(t);
                 if (possibleTemporaryException.isPresent()) {
                     context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TEMPORARY)
                             .statusMessage(possibleTemporaryException.get().getMessage())
                             .statusAttributeException(possibleTemporaryException.get()).create());
                 } else {
-                    logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), ex);
+                    logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), t);
                     context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR)
-                            .statusMessage(ex.getMessage())
-                            .statusAttributeException(ex).create());
+                            .statusMessage(t.getMessage())
+                            .statusAttributeException(t).create());
+                }
+                if (t instanceof Error) {
+                    //Re-throw any errors to be handled by and set as the result of evalFuture
+                    throw t;
                 }
-                onError(graph, context);
             } finally {
                 // todo: timer matter???
                 //timerContext.stop();
@@ -511,19 +515,23 @@ public class SessionOpProcessor extends AbstractEvalOpProcessor {
                                 .statusAttributes(attributes)
                                 .create());
 
-                    } catch (Exception ex) {
-                        final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(ex);
+                    } catch (Throwable t) {
+                        onError(graph, context);
+                        final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(t);
                         if (possibleTemporaryException.isPresent()) {
                             context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TEMPORARY)
                                     .statusMessage(possibleTemporaryException.get().getMessage())
                                     .statusAttributeException(possibleTemporaryException.get()).create());
                         } else {
-                            logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), ex);
+                            logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), t);
                             context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR)
-                                    .statusMessage(ex.getMessage())
-                                    .statusAttributeException(ex).create());
+                                    .statusMessage(t.getMessage())
+                                    .statusAttributeException(t).create());
+                        }
+                        if (t instanceof Error) {
+                            //Re-throw any errors to be handled by and set as the result the FutureTask
+                            throw t;
                         }
-                        onError(graph, context);
                     }
 
                     return null;
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
index 9ee9262a15..824fb216ed 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
@@ -247,19 +247,23 @@ public class TraversalOpProcessor extends AbstractOpProcessor {
                     }
                     onError(graph, context);
                 }
-            } catch (Exception ex) {
-                final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(ex);
+            } catch (Throwable t) {
+                onError(graph, context);
+                final Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(t);
                 if (possibleTemporaryException.isPresent()) {
                     context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TEMPORARY)
                             .statusMessage(possibleTemporaryException.get().getMessage())
                             .statusAttributeException(possibleTemporaryException.get()).create());
                 } else {
-                    logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), ex);
+                    logger.warn(String.format("Exception processing a Traversal on request [%s].", msg.getRequestId()), t);
                     context.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR)
-                            .statusMessage(ex.getMessage())
-                            .statusAttributeException(ex).create());
+                            .statusMessage(t.getMessage())
+                            .statusAttributeException(t).create());
+                    if (t instanceof Error) {
+                        //Re-throw any errors to be handled by and set as the result of evalFuture
+                        throw t;
+                    }
                 }
-                onError(graph, context);
             } finally {
                 timerContext.stop();
             }