Repository navigation
Try the next server on failure, and fall back when the lookup fails - #1591
Merged
Merged
Conversation
Look up the API servers once, shuffled, and move on to the next one when a request fails, as the API documentation asks. Fall back to all.api.radio-browser.info when the SRV lookup fails or comes back empty.
4 of 11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change
None for callers. When the DNS lookup of the API servers fails, the client now falls back to
all.api.radio-browser.infoinstead of raising aRadioBrowserConnectionError, so requests that used to fail now go through.Proposed change
Found while comparing with other Radio Browser clients, and with what the API documentation asks of clients: "randomize the list and choose the first entry", and "if a request fails just retry the request with the next entry in the list".
Moving on to the next server. The client used to look up the servers again on every retry and pick one at random, so a retry could land on the server that just failed. It now looks up the servers once, shuffles them, and moves on to the next one when a request fails. Only when every server has been tried, it looks them up again.
A fallback for the lookup. The servers are published as DNS SRV records, which some home routers and DNS filters do not handle well. When that lookup fails or comes back empty, the client now uses
all.api.radio-browser.info, whose plain A and AAAA records point to all API servers, and which the server certificate covers. pyradios, radiobrowser4j and several other clients use that name as their main way to find the servers. A hard-coded list of servers would go stale:nl1,at1andfi1from older documentation no longer exist.For the record: right now the API has a single server,
de1, so moving on to the next server pays off once there are more again. The fallback helps today.Checked live: the normal lookup picks
de1, and with the SRV lookup made to fail, requests go toall.api.radio-browser.infoand succeed.Type of change
Additional information
Checklist
poetry run pytestpasses locally. A pull request cannot be merged unless CI is green.poetry run prek run --all-filespasses (lint, format, and type checks).