Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2752

`AiohttpTransport` malfunctions in an eventlet monkey patched app

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Won't Do
    • 3.6.0, 3.5.2
    • None
    • python
    • None
    • python 3.8, running both natively on macOS, and within a Docker container hosted on macOS

    Description

      I'm running an eventlet-based Flask web app, that starts out with a call to

      eventlet.monkey_patch()
      

      and has view functions that use gremlin-python to connect to a gremlin server.

      I've found that if the browser issues several requests in rapid succession, it can provoke the

      RuntimeError: Cannot run the event loop while another loop is running
      

      error. Passing

      call_from_event_loop=True
      

      when constructing the DriverRemoteConnection just leads to a different type of error, because the problem is transient, not consistent.

      I've developed a minimal example that demonstrates the issue, and can share a link to that if it would be helpful.

      Possible solution:

      How about supplying another transport, besides the AiohttpTransport class, which uses the websocket-client python package, instead of aiohttp?

      I've made one which is very rudimentary but, in testing so far, works fine and solves this issue:

      from gremlin_python.driver.transport import AbstractBaseTransport
      import websocket
      
      
      class WebsocketTransport(AbstractBaseTransport):
      
          def __init__(self, **kwargs):
              self.ws = websocket.WebSocket(**kwargs)
      
          def connect(self, url, headers=None):
              headers = headers or []
              self.ws.connect(url, header=headers)
      
          def write(self, message):
              self.ws.send_binary(message)
      
          def read(self):
              return self.ws.recv()
      
          def close(self):
              self.ws.close()
      
          @property
          def closed(self):
              return not self.ws.connected
      
      
      def transport_factory():
          return WebsocketTransport()
      

      Happy to open this as a PR, if it seems like a good idea.

      Attachments

        Activity

          People

            Unassigned Unassigned
            skieffer Steve Kieffer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: