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

Unexpected suppressing of asyncio.CancelledError exception #2381

Closed
1 task done
decaz opened this issue Sep 29, 2022 · 3 comments
Closed
1 task done

Unexpected suppressing of asyncio.CancelledError exception #2381

decaz opened this issue Sep 29, 2022 · 3 comments

Comments

@decaz
Copy link
Contributor

decaz commented Sep 29, 2022

Environment:

  • Python 3.10.7
  • httpx 0.23.0

Listing:

import asyncio

import httpx


async def request(url):
    async with httpx.AsyncClient() as client:
        try:
            await client.get(url)
        except BaseException as exc:
            print('Request exception', type(exc), exc)
            raise


async def main():
    url = 'http://1.2.3.4:1234/'  # Some unreachable resource with delay
    task = asyncio.create_task(request(url))
    await asyncio.sleep(1)
    task.cancel()
    try:
        await task
    except BaseException as exc:
        print('Task exception', type(exc), exc)


asyncio.run(main())

Expected behavior:

Request exception <class 'asyncio.exceptions.CancelledError'> 
Task exception <class 'asyncio.exceptions.CancelledError'> 

Actual behavior:

Request exception <class 'httpx.ConnectError'> All connection attempts failed
Task exception <class 'httpx.ConnectError'> All connection attempts failed
@tomchristie
Copy link
Member

Answered on the discussion. Thanks for the prompt.

@decaz
Copy link
Contributor Author

decaz commented Sep 29, 2022

@tomchristie I guess the issue should be reopened due to the discussion evolve:

So the problem is there is no certainty which exception will be raised by httpx on cancellation of ongoing request.

Originally posted by @decaz in #2370 (reply in thread)

@tomchristie
Copy link
Member

Let's continue this on #2370

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

2 participants