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

[BUG]: Client connection failure is not handled properly #168

Open
poul1x opened this issue Aug 15, 2022 · 0 comments
Open

[BUG]: Client connection failure is not handled properly #168

poul1x opened this issue Aug 15, 2022 · 0 comments

Comments

@poul1x
Copy link

poul1x commented Aug 15, 2022

  • Python version: 3.9.2
  • Operating System: Debian 10
  • aiohttp version: 3.8.1

Description

Client connection failure is not handled properly when I'm trying to connect to a server which is not running.

What I Did

import asyncio
from aiohttp_sse_client import client as sse_client

async def main():

    async with sse_client.EventSource(
        url="http://no-such-url", max_connect_retry=1
    ) as event_source:

        async for event in event_source:
            print(event)


asyncio.run(main())

# aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host no-such-url:80 ssl:default [Name or service not known]
# Unclosed client session
# client_session: <aiohttp.client.ClientSession object at 0x7f9c9e5d7070>

Temporary solution - passing custom session object. The session is getting closed after exception raised.

import asyncio
from aiohttp import ClientSession
from aiohttp_sse_client import client as sse_client


async def main():

    url = "http://no-such-url"
    async with ClientSession() as session:

        async with sse_client.EventSource(
            url=url, session=session, max_connect_retry=1
        ) as event_source:

            async for event in event_source:
                print(event)


asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant