From e29daf98f3617908e23342388636f24a0383766d Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 2 Apr 2024 02:36:26 +0200 Subject: [PATCH] Ensure DB connections are closed even on erroneous/failing HTTP requests. --- plomtask/http.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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: -- 2.30.2