From 010d7aa49fccf9569e5232d3e2079375a35cc8e7 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 17 Apr 2022 17:32:44 +0700 Subject: [PATCH 1/2] Upgrade SQLAlchemy version and dispose of db engine --- gns3server/core/tasks.py | 5 +++-- gns3server/db/tasks.py | 8 ++++++++ requirements.txt | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gns3server/core/tasks.py b/gns3server/core/tasks.py index 85df5791..5519b808 100644 --- a/gns3server/core/tasks.py +++ b/gns3server/core/tasks.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import sys import asyncio from typing import Callable @@ -25,7 +24,7 @@ from gns3server.controller import Controller from gns3server.compute import MODULES from gns3server.compute.port_manager import PortManager from gns3server.utils.http_client import HTTPClient -from gns3server.db.tasks import connect_to_db, get_computes +from gns3server.db.tasks import connect_to_db, disconnect_from_db, get_computes import logging @@ -90,4 +89,6 @@ def create_shutdown_handler(app: FastAPI) -> Callable: if PortManager.instance().udp_ports: log.warning(f"UDP ports are still used {PortManager.instance().udp_ports}") + await disconnect_from_db(app) + return shutdown_handler diff --git a/gns3server/db/tasks.py b/gns3server/db/tasks.py index 7c40a6fb..46f5a2b7 100644 --- a/gns3server/db/tasks.py +++ b/gns3server/db/tasks.py @@ -51,6 +51,14 @@ async def connect_to_db(app: FastAPI) -> None: log.fatal(f"Error while connecting to database '{db_url}: {e}") +async def disconnect_from_db(app: FastAPI) -> None: + + # dispose of the connection pool used by the database engine + if getattr(app.state, "_db_engine"): + await app.state._db_engine.dispose() + log.info(f"Disconnected from database") + + @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection, connection_record): diff --git a/requirements.txt b/requirements.txt index 7bc97804..2b401fb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ sentry-sdk==1.5.7 psutil==5.9.0 distro==1.7.0 py-cpuinfo==8.0.0 -sqlalchemy==1.4.32 +sqlalchemy==1.4.35 aiosqlite===0.17.0 passlib[bcrypt]==1.7.4 python-jose==3.3.0 From 34233e48d91e697b6fe54a135bd797b66130385b Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 18 Apr 2022 13:25:29 +0700 Subject: [PATCH 2/2] Upgrade FastAPI to version 0.75.2 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2b401fb4..f1496974 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ uvicorn==0.17.6 -fastapi==0.75.0 +fastapi==0.75.2 python-multipart==0.0.5 websockets==10.2 aiohttp==3.8.1