Skip to content

Handle concurrent use of one client - #1599

Merged
frenck merged 1 commit into
mainfrom
frenck/concurrent-use
Oct 2, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/concurrent-use

Conversation

@frenck

@frenck frenck commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Breaking change

None.

Proposed change

One client shared by several tasks, which is how Home Assistant uses it, had three problems:

  • A request that failed late cleared the server another request had just moved on to successfully. A request now only forgets the server it used itself.
  • close() while a request was looking up a server ended that request with an AttributeError. The request now holds on to its session for its whole life, and ends with a RadioBrowserError saying the client was closed.
  • Concurrent first calls of states(country_code=...) each fetched the full country list. A lock makes them share one lookup.

All three come with tests that run the calls concurrently. Found in the fourth review round.

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: None
  • 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.

A request that failed late cleared the server a concurrent request had
just moved on to successfully. Only forget the server a request used
itself. Hold on to the session for the whole request, so close() during
the server lookup ends it with a RadioBrowserError instead of an
AttributeError. Look up the API country names once for concurrent first
calls.
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 2, 2026
@frenck
frenck merged commit b8ac483 into main Oct 2, 2026
31 checks passed
@frenck
frenck deleted the frenck/concurrent-use branch October 2, 2026 09:04
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.

1 participant