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

Aiohttp.web server timeout on long requests. #1541

Closed
owaaa opened this issue Jan 13, 2017 · 4 comments
Closed

Aiohttp.web server timeout on long requests. #1541

owaaa opened this issue Jan 13, 2017 · 4 comments
Labels

Comments

@owaaa
Copy link

owaaa commented Jan 13, 2017

Long story short

Something in aiohttp or asyncio is timing out our web requests that take longer than 60 seconds to complete. We expect long requests and want to configure our server to not timeout on these. I am pretty confident its something inside the aiohttp server as this did not happen when the server was a tornado server before we re-wrote it to aiohttp. Requests end in different places and the following ends up in our logs

 File "/usr/src/app/src/Util/aiohttp/Middleware.py", line 15, in middleware_handler
   response = await handler(request)
 File "/usr/local/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 663, in __await__
   return (yield from self.__iter__())
 File "/usr/local/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 658, in __iter__
   resp = yield from method()
....
 File "/usr/local/lib/python3.5/asyncio/futures.py", line 361, in __iter__
   yield self  # This tells Task to wait for completion.
 File "/usr/local/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
   future.result()
 File "/usr/local/lib/python3.5/asyncio/futures.py", line 266, in result
   raise CancelledError
concurrent.futures._base.CancelledError

We are running the aiohttp server via web.Application such as

web.run_app(app, host='0.0.0.0', port=config.web_port)

It does not appear from the docs that there are any timeout options. I do see some in the lower level server but web.run_app seems to prevent one from setting these.

Expected behaviour

Ability to set desired timeout behavior while configuring the application or during run_app

Actual behaviour

Web requests time out with a cancelled error at 60s

Steps to reproduce

Make a handler with work greater than 60s. Launch application via web.run_app. Invoke handler route and verify work was cancelled after 60s.

Your environment

python 3.5.2. Deployed via Docker on AWS ECS.

@fafhrd91
Copy link
Member

just tried this test

#!/usr/bin/env python3
import asyncio
from aiohttp.web import Application, Response, HTTPOk, run_app


async def intro(request):
    idx = 0
    while True:
        await asyncio.sleep(1.0)
        idx += 1
        print('Secs: %s' % idx)

    return HTTPOk()


async def init(loop):
    app = Application()
    app.router.add_get('/', intro)
    return app


loop = asyncio.get_event_loop()
app = loop.run_until_complete(init(loop))
run_app(app)

with curl -v http://localhost:8080/ easily gets above 60 seconds.

do you use nginx or other proxy in front of aiohttp server?

@fafhrd91
Copy link
Member

btw as i remember elb has 60 sec timeout

@owaaa
Copy link
Author

owaaa commented Jan 16, 2017

Thank you for the fast response. With more testing it does appear to be external to aiohttp. The difference is timing out cancels the task in aiohttp vs it would keep running on our old tornado however I think that is a desirable thing. Going to close unless I hit something else. Thanks

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants