Skip to content

Fix request handling robustness issues - #1554

Merged
frenck merged 1 commit into
mainfrom
frenck/fix-request-handling
Oct 1, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/fix-request-handling

Conversation

@frenck

@frenck frenck commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Breaking change

Mostly bugfixes, but a few behaviors change:

  • aiodns now needs to be at least 4.0 (for query_dns()), and pycares 5.0 or newer is a direct dependency. Home Assistant already ships aiodns==4.0.4.
  • A 4xx response now raises a plain RadioBrowserError right away. It used to raise a RadioBrowserConnectionError after five retries. Code that catches RadioBrowserError (like Home Assistant does) is not affected.
  • A failing DNS lookup raises a RadioBrowserConnectionError instead of a raw aiodns.error.DNSError.
  • Empty comma separated station fields (tags, language, language_codes) are now [] instead of [""].

Proposed change

A set of robustness fixes in the request handling, each with tests.

DNS lookup. The API servers are found through DNS SRV records. That lookup used query(), which is deprecated in aiodns 4, and its errors were not caught at all: a DNSError leaked straight to the caller (Home Assistant catches it separately for that reason) and was never retried. The lookup now uses query_dns(), lives in its own _resolve_host(), raises a RadioBrowserConnectionError on failure or when no SRV records come back, and ignores records that are not SRV.

Escaping. filter_term was joined into the path as is. Checked against the live API:

GET /json/stations/bytagexact/#original     -> 1000 unrelated stations (the rest became a fragment, limit included)
GET /json/stations/bytagexact/%23original   -> REYFM - #original
GET /json/stations/byname/AC/DC             -> 404
GET /json/stations/byname/AC%2FDC           -> AC/DC, ...

Home Assistant browses stations by tag through exactly this path. The filter term and the station UUID are now escaped.

Timeout. The response body was read outside of the asyncio.timeout block, so a server that sent headers and then stalled could hang a request forever.

Retries. raise_for_status turned every HTTP error into a connection error, so a 404 was retried five times and made the client forget its server. A 4xx now raises a RadioBrowserError right away; a 5xx is still retried, since another server may do better.

Models. An empty comma separated field became [""]. It is now an empty list.

Plus a few docstring typos, and countries() no longer claims to return a Stats object.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

  • This PR fixes or closes issue: fixes # None
  • This PR is related to: Add a proper test suite #1553
  • Link to a separate documentation pull request: None

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

- Look up the API servers with query_dns(); query() is deprecated in
  aiodns 4. A failed lookup, or one without SRV records, now raises a
  RadioBrowserConnectionError (and is retried) instead of leaking a raw
  DNSError.
- Escape filter_term and the station UUID in the request path. Terms like
  "#original" or "AC/DC" used to change the URL, returning unrelated
  stations or a 404.
- Read the response body within the request timeout.
- Raise a RadioBrowserError on 4xx responses without retrying; only 5xx
  responses are retried.
- Turn empty comma separated fields into empty lists instead of [""].
- Fix a few docstring typos and the countries() return description.

aiodns now needs to be at least 4.0, and pycares is a direct dependency.
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 1, 2026
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@frenck
frenck merged commit b02798d into main Oct 1, 2026
31 checks passed
@frenck
frenck deleted the frenck/fix-request-handling branch October 1, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants