WSGI specification requires that close() be called on iterable no matter what happens. #824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tornado does not comply with the WSGI specification (PEP 333/3333).
Specifically the WSGI specification says:
"""If the iterable returned by the application has a close() method, the server or gateway must call that method upon completion of the current request, whether the request was completed normally, or terminated early due to an application error during iteration or an early disconnect of the browser."""
Tornado is not calling close() when an unhandled exception propagates all the way up to the WSGIContainer.
This can cause problems for WSGI applications or middleware which rely on close() being called at the end of the request to cleanup resources or end transactions.
The requirement is something that uWSGI, wsgiref, Sentry and others have got wrong at times and has been blogged about in:
http://blog.dscpl.com.au/2012/10/obligations-for-calling-close-on.html
in order to highlight the problem, yet Tornado still has got it wrong.