Skip to content

Commit dcebea3

Browse files
authored
Merge pull request #3320 from lonvia/fix-timeout-return-code
Fix returned HTTP error when query runs too long
2 parents 7321e66 + b3a2b3d commit dcebea3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

nominatim/server/falcon/server.py

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Optional, Mapping, cast, Any, List
1111
from pathlib import Path
1212
import datetime as dt
13+
import asyncio
1314

1415
from falcon.asgi import App, Request, Response
1516

@@ -164,6 +165,8 @@ def get_application(project_dir: Path,
164165
middleware=middleware)
165166
app.add_error_handler(HTTPNominatimError, nominatim_error_handler)
166167
app.add_error_handler(TimeoutError, timeout_error_handler)
168+
# different from TimeoutError in Python <= 3.10
169+
app.add_error_handler(asyncio.TimeoutError, timeout_error_handler)
167170

168171
legacy_urls = api.config.get_bool('SERVE_LEGACY_URLS')
169172
for name, func in api_impl.ROUTES:

nominatim/server/starlette/server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Optional, Mapping, Callable, cast, Coroutine, Dict, Awaitable
1111
from pathlib import Path
1212
import datetime as dt
13+
import asyncio
1314

1415
from starlette.applications import Starlette
1516
from starlette.routing import Route
@@ -144,7 +145,8 @@ def get_application(project_dir: Path,
144145
middleware.append(Middleware(FileLoggingMiddleware, file_name=log_file))
145146

146147
exceptions: Dict[Any, Callable[[Request, Exception], Awaitable[Response]]] = {
147-
TimeoutError: timeout_error
148+
TimeoutError: timeout_error,
149+
asyncio.TimeoutError: timeout_error
148150
}
149151

150152
async def _shutdown() -> None:

0 commit comments

Comments
 (0)