From: Sarah Hoffmann Date: Sat, 27 Jan 2024 18:53:13 +0000 (+0100) Subject: catch special async timeout error in servers X-Git-Tag: v4.4.0~24^2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/b3a2b3d48448ee927768caaa16336d166428b3ba?hp=--cc catch special async timeout error in servers In Python <= 3.10 this is not yet the same as TimeoutError. Fixes #3303. --- b3a2b3d48448ee927768caaa16336d166428b3ba diff --git a/nominatim/server/falcon/server.py b/nominatim/server/falcon/server.py index 5ec418a6..00036795 100644 --- a/nominatim/server/falcon/server.py +++ b/nominatim/server/falcon/server.py @@ -10,6 +10,7 @@ Server implementation using the falcon webserver framework. from typing import Optional, Mapping, cast, Any, List from pathlib import Path import datetime as dt +import asyncio from falcon.asgi import App, Request, Response @@ -164,6 +165,8 @@ def get_application(project_dir: Path, middleware=middleware) app.add_error_handler(HTTPNominatimError, nominatim_error_handler) app.add_error_handler(TimeoutError, timeout_error_handler) + # different from TimeoutError in Python <= 3.10 + app.add_error_handler(asyncio.TimeoutError, timeout_error_handler) legacy_urls = api.config.get_bool('SERVE_LEGACY_URLS') for name, func in api_impl.ROUTES: diff --git a/nominatim/server/starlette/server.py b/nominatim/server/starlette/server.py index 33ab22c7..f793dfde 100644 --- a/nominatim/server/starlette/server.py +++ b/nominatim/server/starlette/server.py @@ -10,6 +10,7 @@ Server implementation using the starlette webserver framework. from typing import Any, Optional, Mapping, Callable, cast, Coroutine, Dict, Awaitable from pathlib import Path import datetime as dt +import asyncio from starlette.applications import Starlette from starlette.routing import Route @@ -144,7 +145,8 @@ def get_application(project_dir: Path, middleware.append(Middleware(FileLoggingMiddleware, file_name=log_file)) exceptions: Dict[Any, Callable[[Request, Exception], Awaitable[Response]]] = { - TimeoutError: timeout_error + TimeoutError: timeout_error, + asyncio.TimeoutError: timeout_error } async def _shutdown() -> None: