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

Client raises asyncio.TimeoutError #7122

Closed
1 task done
poofeg opened this issue Dec 7, 2022 · 7 comments · Fixed by #8968
Closed
1 task done

Client raises asyncio.TimeoutError #7122

poofeg opened this issue Dec 7, 2022 · 7 comments · Fixed by #8968
Labels

Comments

@poofeg
Copy link

poofeg commented Dec 7, 2022

Describe the bug

Client raises asyncio.TimeoutError, although according to the documentation it seems that aiohttp.ServerTimeoutError should be raised.

To Reproduce

  1. Run nc -l 8000
  2. Run:
import aiohttp
import asyncio


async def main():
    timeout = aiohttp.ClientTimeout(total=10)
    async with aiohttp.ClientSession(timeout=timeout) as session:
        try:
            async with session.get('http://127.0.0.1:8000'):
                pass
        except aiohttp.ServerTimeoutError:
            print('aiohttp.ServerTimeoutError')
        except aiohttp.ClientError:
            print('aiohttp.ClientError')
        except asyncio.TimeoutError:
            print('asyncio.TimeoutError')


if __name__ == '__main__':
    asyncio.run(main())
  1. Wait 10 seconds
  2. Get result: "asyncio.TimeoutError"

Expected behavior

Result: "aiohttp.ServerTimeoutError"

Logs/tracebacks

asyncio.TimeoutError

Python Version

3.11.0

aiohttp Version

3.8.3

multidict Version

6.0.2

yarl Version

1.8.1

OS

macOS 12.6.1

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@poofeg poofeg added the bug label Dec 7, 2022
@webknjaz
Copy link
Member

webknjaz commented Dec 7, 2022

Hey @graingert, can this be related to your patch #6877?

@webknjaz
Copy link
Member

webknjaz commented Dec 7, 2022

Looks like the code does raise ServerTimeoutError on (1) connection timeout
(

exc = ServerTimeoutError("Timeout on reading data from socket")
) and on read timeout (
raise ServerTimeoutError(
)

@poofeg
Copy link
Author

poofeg commented Dec 7, 2022

This is not a new behavior. At least since version 2.3.10, this case raises asyncio.TimeoutError exception.

@nick-merrill
Copy link

Thanks for posting this question @poofeg. I had thought we had handled timeouts in our retry logic, but we didn't identify this exception as one that needs to be handled as well.

I would suggest:

  1. Update the documentation to clarify that asyncio.TimeoutError may be raised in the event of a timed-out request.
  2. Consider (but probably avoid) raising ServerTimeoutError instead of asyncio.TimeoutError in this case.

Do people agree the documentation should be updated to call out this behavior?

@Dreamsorcerer
Copy link
Member

@webknjaz @bdraco Any opinion on these timeouts?
Currently (atleast on master), ConnectionTimeoutError is thrown for connect and sock_connect, SocketTimeoutError for sock_read, and TimeoutError for total.
As it's a total timeout, not specific to the server connection, maybe it makes sense to keep as a TimeoutError?

Also, I noticed that ClientResponse.start() reenters the same timer context that is already being used in the parent Client._request() call, which seems redundant.

but we didn't identify this exception as one that needs to be handled as well.

Not as well. It's the only one that needs to be handled as it is the parent for all timeout exceptions.

@Dreamsorcerer
Copy link
Member

Also, I noticed that ClientResponse.start() reenters the same timer context that is already being used in the parent Client._request() call, which seems redundant.

This could have been planned for future timeouts though (there are several proposed timeouts commented out in ClientTimeout).

@bdraco
Copy link
Member

bdraco commented Sep 1, 2024

I don't have a strong opinion either way as long as the docs reflect what actually happens. I would consider this issue closed by the changes proposed in #8968

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

Successfully merging a pull request may close this issue.

5 participants