ensure context cleanup runs even if teardown raises

This commit is contained in:
Kadir Can Ozden 2026-02-20 03:49:10 +03:00
parent 7b0088693e
commit 913b2b6a35

View file

@ -484,13 +484,17 @@ class AppContext:
try:
if self._request is not None:
self.app.do_teardown_request(self, exc)
self._request.close()
try:
self.app.do_teardown_request(self, exc)
finally:
self._request.close()
finally:
self.app.do_teardown_appcontext(self, exc)
_cv_app.reset(self._cv_token)
self._cv_token = None
appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync)
try:
self.app.do_teardown_appcontext(self, exc)
finally:
_cv_app.reset(self._cv_token)
self._cv_token = None
appcontext_popped.send(self.app, _async_wrapper=self.app.ensure_sync)
def __enter__(self) -> te.Self:
self.push()