Issue with building /search path
## What did you search for?
Query: `Warszawa`
Endpoint: `GET /api/search?q=Warszawa&format=jsonv2&limit=1`
(Self-hosted Nominatim, not `nominatim.openstreetmap.org`.)
## What result did you get?
Intermittently, one pod returns:
`HTTP 404 {"title":"404 Not Found"}`
At the same time on that same pod:
- `GET /api/reverse?lat=52.2297&lon=21.0122&format=jsonv2` -> `200`
- `GET /api/status` -> `200`
Another pod in the same deployment (same DB) returns `200` for the same `/api/search` request.
## Further details
### What is wrong
`/search` is sometimes not registered during API startup.
This creates a partially working pod: reverse/status work, but search is permanently `404` on that pod until process reload/restart.
### Why this happens
In `nominatim_api/v1/server_glue.py` (`get_routes()`), the `/search` route is appended only after a DB/table check.
If DB is briefly unavailable during startup, the exception is swallowed (`except ...: pass`), so startup continues without `/search`.
Routes are initialized once in startup (`nominatim_api/server/falcon/server.py`, `process_startup()`), so the pod stays in this broken state.
### How we confirmed it
- Repro on official image `mediagis/nominatim:5.2.0`.
- Reloading gunicorn workers (`kill -HUP 1`) immediately restores `/api/search` to `200`.
- Restarting pod after DB is fully ready also restores normal behavior.
## Proposed fix (single, simplest, and most robust)
Always register `/search` unconditionally at startup, and handle DB availability at request time.
Implementation direction:
1. In `nominatim_api/v1/server_glue.py`:
- add `('search', search_endpoint)` to routes unconditionally,
- remove conditional registration based on startup DB check.
2. In `search_endpoint`:
- catch DB connectivity/table errors and return `503` (service temporarily unavailable), not `404`.
3. Keep DB checks in health/readiness logic, not in route registration.
This removes startup race conditions and guarantees stable API surface: endpoint exists consistently, even if DB is temporarily unavailable.
### Versions
- Nominatim app: `5.2.0-0`
- Nominatim DB schema version (`nominatim_properties.database_version`): `5.2.0-0`
- PostgreSQL: `16.9` (Percona distribution)
关闭于 2026-03-05 5 条评论