You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by GitBox <gi...@apache.org> on 2018/12/31 14:20:39 UTC

[GitHub] spmallette closed pull request #1023: TINKERPOP-2105 fix for TP33

spmallette closed pull request #1023: TINKERPOP-2105 fix for TP33
URL: https://github.com/apache/tinkerpop/pull/1023
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/client.py b/gremlin-python/src/main/jython/gremlin_python/driver/client.py
index faf4ca4e66..ec3d2ece96 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/client.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/client.py
@@ -75,6 +75,10 @@ def __init__(self, url, traversal_source, protocol_factory=None,
         self._pool = queue.Queue()
         self._fill_pool()
 
+    @property
+    def available_pool_size(self):
+        return self._pool.qsize()
+
     @property
     def executor(self):
         return self._executor
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/connection.py b/gremlin-python/src/main/jython/gremlin_python/driver/connection.py
index bff190418e..26104eebf1 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/connection.py
@@ -63,6 +63,7 @@ def cb(f):
                 f.result()
             except Exception as e:
                 future.set_exception(e)
+                self._pool.put_nowait(self)
             else:
                 # Start receive task
                 done = self._executor.submit(self._receive)
@@ -73,9 +74,11 @@ def cb(f):
         return future
 
     def _receive(self):
-        while True:
-            data = self._transport.read()
-            status_code = self._protocol.data_received(data, self._results)
-            if status_code != 206:
-                break
-        self._pool.put_nowait(self)
+        try:
+            while True:
+                data = self._transport.read()
+                status_code = self._protocol.data_received(data, self._results)
+                if status_code != 206:
+                    break
+        finally:
+            self._pool.put_nowait(self)
diff --git a/gremlin-python/src/main/jython/tests/driver/test_client.py b/gremlin-python/src/main/jython/tests/driver/test_client.py
index fbfe2d7cc7..63a486cceb 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_client.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_client.py
@@ -49,6 +49,19 @@ def test_client_eval_traversal(client):
     assert len(client.submit('g.V()').all().result()) == 6
 
 
+def test_client_connection_pool_after_error(client):
+    # Overwrite fixture with pool_size=1 client
+    client = Client('ws://localhost:45940/gremlin', 'gmodern', pool_size=1)
+
+    try:
+        # should fire an exception
+        client.submit('1/0').all().result()
+        assert False
+    except Exception:
+        # expecting the pool size to be 1 again after query returned
+        assert client.available_pool_size == 1
+
+
 def test_client_bytecode(client):
     g = Graph().traversal()
     t = g.V()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services