From: Christian Heller Date: Tue, 2 Apr 2024 00:36:26 +0000 (+0200) Subject: Ensure DB connections are closed even on erroneous/failing HTTP requests. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/static/condition?a=commitdiff_plain;h=e29daf98f3617908e23342388636f24a0383766d;p=plomtask Ensure DB connections are closed even on erroneous/failing HTTP requests. --- diff --git a/plomtask/http.py b/plomtask/http.py index 5b7100c..f368232 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -110,10 +110,11 @@ class TaskHandler(BaseHTTPRequestHandler): return else: raise NotFoundException(f'Unknown page: /{site}') - conn.close() self._send_html(html) except HandledException as error: self._send_msg(error, code=error.http_code) + finally: + conn.close() def do_GET_calendar(self, conn: DatabaseConnection, params: ParamsParser) -> str: @@ -160,10 +161,11 @@ class TaskHandler(BaseHTTPRequestHandler): else: msg = f'Page not known as POST target: /{site}' raise NotFoundException(msg) - conn.close() self._redirect('/') except HandledException as error: self._send_msg(error, code=error.http_code) + finally: + conn.close() def do_POST_day(self, conn: DatabaseConnection, params: ParamsParser, form_data: PostvarsParser) -> None: