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

Server handler halts after client connection closed #2595

Closed
ykvch opened this issue Dec 6, 2017 · 3 comments
Closed

Server handler halts after client connection closed #2595

ykvch opened this issue Dec 6, 2017 · 3 comments
Labels
invalid This doesn't seem right outdated

Comments

@ykvch
Copy link

ykvch commented Dec 6, 2017

Pre:

Linux with curl installed.
Python 3.6.3 with aiohttp installed

Server script (server.py):

# coding: utf-8

from asyncio import sleep
from aiohttp import web


async def handle_stream(request):
    data = 'Їїїїї'
    resp = web.StreamResponse()
    resp.content_length = len(data)
    await resp.prepare(request)

    resp.write(data.encode("utf-8"))
    await sleep(1)  # if sleep present, handle ends here, next line not executed
    raise RuntimeError("this should happen")


app = web.Application()
app.router.add_get("/", handle_stream)
web.run_app(app)

Steps:

  1. Run server script: python server.py
  2. On the same host run (bash): curl -vv http://127.0.0.1:8080/
  3. Observe server.py script console output.

Expected:

  1. RuntimeError("this should happen") message 1 second after client disconnects.

Actual:

  1. Server runs without messages (raise... line never executed)

Note: If await sleep... line (above the raise...) removed then exception does get triggered.

@ykvch ykvch changed the title handler halts after client connection closed Server handler halts after client connection closed Dec 6, 2017
@fafhrd91
Copy link
Member

fafhrd91 commented Dec 6, 2017

This is expected behavior, await sleep raises CancelledError

@ykvch
Copy link
Author

ykvch commented Dec 6, 2017

Thanks.
Now it clearly looks like a duplicate/similar to #1430

Solution:
Explicitly use shield around anything that has to be executed independently of connection cancellation.

@lock
Copy link

lock bot commented Oct 28, 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].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

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

No branches or pull requests

3 participants