]> git.openstreetmap.org Git - nominatim.git/commitdiff
properly close connections when shutting down starlette
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 26 May 2023 09:44:25 +0000 (11:44 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 26 May 2023 11:53:34 +0000 (13:53 +0200)
nominatim/server/starlette/server.py

index a2a70ebf0cb4a62c547ed618d6bae4c271b6dc0c..f81b122f274e17ddf0e0565139b09e003663a05e 100644 (file)
@@ -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)