-
Notifications
You must be signed in to change notification settings - Fork 216
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
Clarifying HTTP exception behavior wrt. 500 responses. #64
Comments
Behavior now changed in uvicorn 0.3.5. |
So what needs doing here - clarification in the spec and also a fix to |
Not some much a clarification in the spec (since it doesn't yet discuss exceptions from the ASGI callable, aside from send/receive exceptions), as an addition. I suppose at some point the HTTP section ought to have an The main overview currently has an "exceptions" section which could note that "exceptions raised by the ASGI application should close the connection, and may also return an appropriate error message, such as an HTTP 500 response (then link to HTTP spec for fuller details)." And yes, also a fix to the middleware. I'll start by considering the docs change as being on my backlog, but equally happy if you or anyone else is able to get there first. |
OK - I won't be able to get to either in the short term, but will leave this open to track the work. |
Related to this may be some tightening up on specification around how exceptions within |
Hmm, is there a reason to not raise a known error if you |
Okay, I'm going to open a seperate ticket to discuss this (#66) since I think it's a bit of a thorny question, and really it's seperate to this ticket which is "how should applications handle exception, particularly wrt. issuing technical 500 responses", and which I think is basically resolved. |
@tomchristie Do you think there's more work we need to do here? |
Related: #54
Having worked through the implementation implications in both uvicorn and starlette, I'm now confident that the behaviors should be:
Both Uvicorn's WSGI middleware and asgiref's
WsgiToAsgi
appear to have incorrect behavior here, in that they raiseexc_info
immediately in both cases, rather than sending an application's 500 response that is returned alongside with theexc_info
and then raising the exception. (End result - the server gets to log the exception and returns a 500 response, but we don't get any application-defined 500 responses, either traceback or user-facing 500s)An example of what I've used to test server/application interaction for resolving this wrt uvicorn's middleware... Taken from the WSGI spec
Here's my resolution to the issue in uvicorn - note that
exc_info
needs to be raised not at the end ofstart_response
(since we don't have the response body yet) but after all of the returned byte-iterator has been sent to the send channel.The text was updated successfully, but these errors were encountered: