ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

Pyarango Persistent Connection Hangs for Up to 15 mins #239

Closed joeltgray closed 1 year ago

joeltgray commented 1 year ago

I'm using Pyarango in a Kuberenetes multinode scenario. In the event of a node death, my Pyarango connection hangs for around 15 minutes before it times out.

I've found that I can manually run "connection.resetSession" which helps but I don't want to always be forcing a new connection.

I can't seem to see anything that allows us to check the current connection? A function like "connection.connected" returning a bool or something would be a good feature to add, as it would allow me to check the existing connection periodically and only force a reset is the connection has been dropped.

If it already exists would someone please let me know?

Thanks!

joeltgray commented 1 year ago

Until recently I had been using a monkey patch call to overcome this:

This monkey patch is in place to patch the PyArango library AikidoSession to include a http connection timeout header to stop ArangoDB connections from hanging for long periods when connections are stale. Prevents hanging connections when node death occurs in multinode Kubernetes configuration

AikidoSession.Holder._base_call = AikidoSession.Holder.__call__
def _monkey_patch_call(self, *args, **kwargs):
  kwargs["timeout"] = 10
  return self._base_call(*args, **kwargs)

AikidoSession.Holder.__call__ = _monkey_patch_call

Now that I've finally found the time, I've made amendments to the PyArango library as I think this is an important http header to be included for all users to have a more granular control over their connection to ArangoDB while using PyArango.

Please see related Pull Request.

joeltgray commented 1 year ago

Linking related Pull Request: #242

joeltgray commented 1 year ago

Closing as fix has been merged from #242!