-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
response return value runtime check #3321
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
Also, a test is required to never miss the functionality after code refactoring. |
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:
with debug check:
|
|
…nitogf/aiohttp into response-return-runtime-check
There was a problem hiding this 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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check prevents the log.debug
last value being overwritten by: https://github.com/aio-libs/aiohttp/pull/3321/files/8d585c826f9fb6fc82a5291f5973caf136aaabee#diff-8ac506a3012476288a758f156ca7d7b2R449 and fail the assert: https://github.com/aio-libs/aiohttp/pull/3321/files/8d585c826f9fb6fc82a5291f5973caf136aaabee#diff-98519d3deafe019f57304a557d20531cR542
maybe there's a way to test it w/o relying on the last log.debug
value?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Agree
aiohttp/web_protocol.py
Outdated
if not isinstance(resp, StreamResponse): | ||
self.log_debug("Possibly missing return " | ||
"statement on request handler") | ||
raise RuntimeError('Web-handler should \ |
There was a problem hiding this comment.
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.
thanks! |
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. |
#3311