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

Raise a error if web-handler returned non-response in debug mode. #3311

Closed
benitogf opened this issue Oct 2, 2018 · 9 comments
Closed

Raise a error if web-handler returned non-response in debug mode. #3311

benitogf opened this issue Oct 2, 2018 · 9 comments

Comments

@benitogf
Copy link
Contributor

benitogf commented Oct 2, 2018

Long story short

Opening this as mentioned here: #3223 (comment)

Unhandled exception
Traceback (most recent call last):
  File "/tmp/tmpg2n5yr0j/pypi__aiohttp_3_4_4/aiohttp/web_protocol.py", line 410, in start
    await resp.prepare(request)
AttributeError: 'NoneType' object has no attribute 'prepare'

Expected behaviour

It should't trow

Actual behaviour

There's an unhandled exception thrown

Steps to reproduce

This happens in a websocket route handler when a client disconnects

Your environment

aiohttp 3.4.4
OS centos
no proxy

@aio-libs-bot
Copy link

GitMate.io thinks possibly related issues are #255 (Handling WebSocket disconnects), #1661 (Client exceptions refactoring), #3223 (Should not throw exception for EofStream Exception in WebSocket.), #2368 (Can't detect disconnection on wifi websocket client ), and #3291 (Websocket client hanging/blocking?).

@yogeshsajanikar
Copy link

I have same issue with streaming response.

@asvetlov
Copy link
Member

asvetlov commented Oct 3, 2018

Guys, looks like you both don't return a response object from failed web-handler.

@benitogf
Copy link
Contributor Author

benitogf commented Oct 4, 2018

Thanks @asvetlov I was missing the return statement at the end of the handler https://aiohttp.readthedocs.io/en/stable/web_quickstart.html#websockets

@asvetlov
Copy link
Member

asvetlov commented Oct 4, 2018

That's exactly what I was suspected.
Runtime check for the return value is quite expensive but we can do it in debug mode (loop.get_debug()).

The patch is trivial, a champion is needed.

@asvetlov asvetlov added enhancement good first issue Good for newcomers server and removed bug labels Oct 4, 2018
@asvetlov asvetlov changed the title Unhandled exception thrown on websocket client disconnect Raise a error if web-handler returned non-response in debug mode. Oct 4, 2018
@benitogf
Copy link
Contributor Author

benitogf commented Oct 4, 2018

@asvetlov please review above patch, I saw no use of loop.get_debug() in web_protocol so used what was around

@asvetlov
Copy link
Member

asvetlov commented Oct 4, 2018

The idea is dropping custom debug checks everywhere in the server and rely on loop.get_debug() only.
The change is scheduled to aiohttp 4.0, so self.debug check is correct now.

@asvetlov
Copy link
Member

asvetlov commented Oct 5, 2018

Fixed by #3321

@asvetlov asvetlov closed this as completed Oct 5, 2018
@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.
Projects
None yet
Development

No branches or pull requests

4 participants