I find it pretty annoying to handle the close() method of AsyncOpensearch. Basically, once closed, the client becomes unusable because every attempt to connect to the Opensearch cluster will yield the error opensearchpy.exceptions.ConnectionError: ConnectionError(Session is closed) caused by: RuntimeError(Session is closed).
Is your feature request related to a problem?
I find it pretty annoying to handle the
close()
method ofAsyncOpensearch
. Basically, once closed, the client becomes unusable because every attempt to connect to the Opensearch cluster will yield the erroropensearchpy.exceptions.ConnectionError: ConnectionError(Session is closed) caused by: RuntimeError(Session is closed)
.What solution would you like?
This happens because
close()
effectively closes theaiohttp.ClientSession
without removing the attribute fromAsyncHttpSession
. A simple solution would be to writeself.session = None
right after https://github.com/opensearch-project/opensearch-py/blob/e323ab2435a26ffd21104a2c765f9711b8614c3a/opensearchpy/connection/http_async.py#L279.What alternatives have you considered?
Re-creating the
AsyncOpensearch
instance, which bring unecessary overhead?Do you have any additional context?
How to create a
RuntimeError
: