From 75aa3cc9bd6b43c0465a65d98372a4f9d0a59f68 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 26 May 2023 11:44:25 +0200 Subject: [PATCH 1/1] properly close connections when shutting down starlette --- nominatim/server/starlette/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) -- 2.39.5