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

response return value runtime check #3321

Merged
merged 16 commits into from
Oct 5, 2018
Merged

response return value runtime check #3321

merged 16 commits into from
Oct 5, 2018

Conversation

benitogf
Copy link
Contributor

@benitogf benitogf commented Oct 4, 2018

@codecov-io
Copy link

codecov-io commented Oct 4, 2018

Codecov Report

Merging #3321 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3321      +/-   ##
==========================================
+ Coverage      98%   98.01%   +0.01%     
==========================================
  Files          43       43              
  Lines        8018     8025       +7     
  Branches     1355     1356       +1     
==========================================
+ Hits         7858     7866       +8     
  Misses         66       66              
+ Partials       94       93       -1
Impacted Files Coverage Δ
aiohttp/helpers.py 97.46% <100%> (ø) ⬆️
aiohttp/web_protocol.py 92.52% <100%> (+0.49%) ⬆️
aiohttp/client_reqrep.py 97.49% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 564c43f...3f6020b. Read the comment docs.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should be isinstance(resp, StreamResponse).
Please move it outside of try/except just before resp.prepare() call.
In check reraise a RuntimeError exception to log it one level upper and close the connection to client.
The check should be performed in debug mode only for sake of performance.

@asvetlov
Copy link
Member

asvetlov commented Oct 4, 2018

Also, a test is required to never miss the functionality after code refactoring.

@benitogf
Copy link
Contributor Author

benitogf commented Oct 4, 2018

The check should be performed in debug mode only for sake of performance.

I don't follow this part, how is checking if we are in debug mode different from checking the resp type?

w/o debug check:

                    if isinstance(resp, StreamResponse):
                        await resp.prepare(request)
                        await resp.write_eof()
                    else:
                        raise RuntimeError('Possibly missing return ' +
                                        ' statement on request handler')

with debug check:

                if self._loop.get_debug():
                    if isinstance(resp, StreamResponse):
                        await resp.prepare(request)
                        await resp.write_eof()
                    else:
                        raise RuntimeError('Possibly missing return ' +
                                        ' statement on request handler')
                else:
                    await resp.prepare(request)
                    await resp.write_eof()

@asvetlov
Copy link
Member

asvetlov commented Oct 4, 2018

                if self.debug:
                    if inot sinstance(resp, StreamResponse):
                        raise RuntimeError('Web-handler should return a response instance, got {!r}'.format(resp))
                await resp.prepare(request)
                await resp.write_eof()

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done.

I have no idea what did you wrong with git but your PR has not only your changes but many unrelated fixes as well.
I suspect it is a result of rebasing.

Note: aiohttp uses squash-and-merge strategy for applying PRs.
It means you don't need to rebase, merge from master only if needed.
Guthub manages the rebasing pretty well.

@@ -438,7 +445,7 @@ def _process_keepalive(self):
self.log_exception('Unhandled exception', exc_info=exc)
self.force_close()
finally:
if self.transport is None:
if self.transport is None and resp is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the check, self.force_close() implies setting self.transport to None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got you.
Let's drop self.log_debug("Possibly missing return statement on request handler") log but log RuntimeError with it's message.

'Web-handler should return a response instance, got {!r}' is a good enough hint to the missing return statement, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, that runtimeError will be bypassed by this one: https://github.com/aio-libs/aiohttp/pull/3321/files/8d585c826f9fb6fc82a5291f5973caf136aaabee#diff-8ac506a3012476288a758f156ca7d7b2R439 another reason why I used log.debug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Agree

if not isinstance(resp, StreamResponse):
self.log_debug("Possibly missing return "
"statement on request handler")
raise RuntimeError('Web-handler should \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace \ with implicit strings concatenation as a line above.

@asvetlov
Copy link
Member

asvetlov commented Oct 5, 2018

thanks!

@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
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants