Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Re-create aiohttp.ClientSession after using close() on AsyncOpensearch #637

Closed
odelmarcelle opened this issue Dec 20, 2023 · 1 comment · Fixed by #639
Closed
Labels
enhancement New feature or request

Comments

@odelmarcelle
Copy link
Contributor

Is your feature request related to a problem?

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).

What solution would you like?

This happens because close() effectively closes the aiohttp.ClientSession without removing the attribute from AsyncHttpSession. A simple solution would be to write self.session = None right after

await self.session.close()
.

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:

import asyncio
from opensearchpy import AsyncOpenSearch
loop = asyncio.get_event_loop()
opensearch = AsyncOpenSearch(...)
async def get_health():
    print(await opensearch.cluster.health())

loop.run_until_complete(get_health())         # Ok
loop.run_until_complete(opensearch.close())   # Closing
loop.run_until_complete(get_health())         # RuntimeError
@odelmarcelle odelmarcelle added enhancement New feature or request untriaged Need triage labels Dec 20, 2023
@dblock
Copy link
Member

dblock commented Dec 20, 2023

This is a good catch, definitely a problem. There should be a way to use with for any connection/instance, too. Please contribute!

@dblock dblock removed the untriaged Need triage label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants