Skip to content

v1.5.2 - Socket leak and single-result language fixes

Latest

Choose a tag to compare

@LavX LavX released this 26 Oct 23:36

Highlights

Patch release with two fixes from @zdimension: a socket leak that eventually took the service down with "Too many open files", and a language detection bug that hid subtitles when a search had exactly one result.

Bug fix: replaced HTTPS adapters are now closed on TLS cipher rotation (#20)

The vendored cloudscraper rotates its TLS cipher suite before nearly every request by mounting a fresh CipherSuiteAdapter. The previous adapter was never closed, and it was never garbage collected either, because its SSL context holds a bound method back to the adapter. Its pooled keep-alive connection stayed open for the life of the process and sat in CLOSE_WAIT once the server dropped it. That is one leaked socket per request, so after a few days the process hit its file descriptor limit and uvicorn's accept loop failed with OSError: [Errno 24] Too many open files. If you have been restarting the container on a schedule to work around this, you should no longer need to.

  • vendor/cloudscraper/__init__.py: _rotate_tls_cipher_suite() now closes the replaced adapter right after mounting the new one. A response still streaming from the old adapter finishes normally, and its connection is released when it completes.
  • tests/test_vendored_cloudscraper.py: new tests that load vendor/cloudscraper directly. CI installs vendor/cloudscraper-3.0.0.zip, so a plain import cloudscraper never exercised the vendored copy that main.py actually runs.

Bug fix: language of single-subtitle detail pages is detected correctly (#19)

When a language-filtered search has exactly one result, OpenSubtitles redirects to that subtitle's detail page. The parser took the language from the page's canonical link, falling back to the URL it was given, but detail pages have no canonical link and the scraper passed the original search URL (/en/search/sublanguageid-fre/...). The language was then read from the /en/ path segment, so a French subtitle was labeled English and dropped by the language filter. In Bazarr this showed up as a manual search listing fewer results than the website, or no download at all.

  • src/core/scraper.py: the parser now receives the final URL after redirects instead of the original search URL.
  • src/parsers/subtitle_parser.py: when there is no canonical link, the language is read from the page's hreflang="en" alternate link, which carries the same /subtitles/{id}/{slug}-{lang} path.

Verification

  • 488 unit tests pass, including 3 new tests for #19 and 2 for #20. The new tests fail on v1.5.1.
  • Socket leak reproduced against a local keep-alive HTTPS server: 50 requests left 50 client sockets open on v1.5.1, and 1 (the live adapter's pooled connection) on v1.5.2.
  • A response streamed through an adapter that gets rotated out mid-read completes intact.
  • Service starts and /health reports version 1.5.2.

Credits

Big thanks to @zdimension, a first-time contributor, for both fixes in #19 and #20. The leak write-up in particular was excellent: a clear root cause, a minimal fix, and a real-world symptom that made it easy to verify. Welcome aboard!

Full changelog

v1.5.1...v1.5.2