From: Sarah Hoffmann Date: Fri, 26 May 2023 09:44:25 +0000 (+0200) Subject: properly close connections when shutting down starlette X-Git-Tag: v4.3.0~74^2~6 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/75aa3cc9bd6b43c0465a65d98372a4f9d0a59f68?ds=sidebyside;hp=0843fefad3c5f4bb669ce10ae4cee89361166bb8 properly close connections when shutting down starlette --- diff --git a/nominatim/server/starlette/server.py b/nominatim/server/starlette/server.py index a2a70ebf..f81b122f 100644 --- a/nominatim/server/starlette/server.py +++ b/nominatim/server/starlette/server.py @@ -78,7 +78,11 @@ def get_application(project_dir: Path, if config.get_bool('CORS_NOACCESSCONTROL'): middleware.append(Middleware(CORSMiddleware, allow_origins=['*'])) - app = Starlette(debug=debug, routes=routes, middleware=middleware) + async def _shutdown() -> None: + await app.state.API.close() + + app = Starlette(debug=debug, routes=routes, middleware=middleware, + on_shutdown=[_shutdown]) app.state.API = NominatimAPIAsync(project_dir, environ)