Fix request resource leak when teardown handlers raise#5911
Fix request resource leak when teardown handlers raise#5911THE-Amrit-mahto-05 wants to merge 1 commit intopallets:mainfrom
Conversation
|
From the docs: https://flask.palletsprojects.com/en/stable/reqcontext/#teardown-callbacks
There are a lot more places than this in |
|
@davidism |
|
What I'm saying is that adding a I've been working on closing resources over in Werkzeug's tests, maybe that's what prompted you to look at this. I'm also working on that here, just haven't pushed the changes yet. Thanks for pointing out this area, if nothing else I'll move the appcontext teardown out of the |
Ensure that
request.close()is always executed even ifdo_teardown_request()raises an exception.Currently, if a user-defined teardown handler raises an exception,
request.close()is skipped, which can lead to resource leaksThis change wraps teardown execution in a
try/finallyblock toguarantee cleanup without altering normal behavior.