-
-
Notifications
You must be signed in to change notification settings - Fork 805
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
Add error handling and enable graceful shutdown #2131
base: main
Are you sure you want to change the base?
Conversation
channels/generic/http.py
Outdated
if not logger.hasHandlers(): | ||
handler = logging.StreamHandler() | ||
formatter = logging.Formatter( | ||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.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.
Adding the logging call is fine I guess, but I don't think we should be adding handlers for users. That's up to them.
channels/generic/http.py
Outdated
|
||
Note that the ASGI spec requires that the protocol server only starts | ||
sending the response to the client after ``self.send_body`` has been | ||
called the first time. |
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.
Can you undo all of these unrelated changes to comments please.
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.
I am so sorry about these
if not message.get("more_body"): | ||
try: | ||
await self.handle(b"".join(self.body)) | ||
except Exception: | ||
logger.error(f"Error in handle(): {traceback.format_exc()}") | ||
await self.send_response(500, b"Internal Server Error") |
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.
So this is the essence of the proposal.
channels/generic/http.py
Outdated
try: | ||
await self.disconnect() | ||
await aclose_old_connections() | ||
except Exception as e: | ||
logger.error(f"Error during disconnect: {str(e)}") | ||
finally: | ||
raise StopConsumer() |
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 is an extra.
Made the changes as requested |
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.
Thanks @IronJam11. I need to test this against an actual application, so give me a cycle.
channels/generic/http.py
Outdated
if not message.get("more_body"): | ||
try: | ||
await self.handle(b"".join(self.body)) | ||
except Exception: | ||
logger.error(f"Error in handle(): {traceback.format_exc()}") |
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.
What do you think about using logger.exception() ?
I was a bit caught up with a hackathon. apologies for the wait. |
No problem. No rush. I need to find a cycle to sit down with this properly. 👀 |
PR Description:
Closes #1350
Deliverables:
handle()
function.Changes:
Error Handling in
handle()
:handle()
function execution.logger.error()
.500 Internal Server Error
response usingself.send_response()
when an error occurs.Graceful Shutdown:
self.send_response()
.Improved Error Handling in
http_disconnect()
: