Skip to content

fix(tv): synchronize requests.Session and CookieJar access across concurrent threads #73

Done

Description

@mlgitdev

Description

TVClient shares a single requests.Session (self._s) across ScreenerWorker, TapeWorker, NewsPrefetcher, tv-auth-check, and multi-threaded WSGI HTTP request handlers. set_cookies() calls self._s.cookies.clear() and .set(...) under self._lock, while HTTP calls (scan, headlines, story, check_auth, get_watchlists, add_to_watchlist) access self._s without synchronization. requests.Session and RequestsCookieJar are not thread-safe, risking RuntimeError: dictionary changed size during iteration and pool corruption.

References: app/tv_client.py:40, 62-72, 97, 153, 172, 181, 196, 231, 241

Steps to Reproduce

  1. Run NewsAlerts during active polling across Screener, Tape, and NewsPrefetcher.
  2. Save Settings repeatedly to invoke TVClient.set_cookies() while scans are in flight.
  3. Observe concurrent mutation of self._s.cookies while worker threads iterate the shared CookieJar.

Expected Behavior

TVClient should use thread-local requests.Session instances (or pass immutable per-request cookie dicts copied under self._lock) so no thread mutates a shared CookieJar during active requests.

Operating System & Version

  • OS: Windows 11 x64 / macOS arm64 / Linux x86_64
  • Version: v2.12.0
  • Display / Scale: Verified via live Chrome CDP (1600x960) & local unit/backend suite

Logs & Additional Context

Backend audit verified set_cookies() mutates shared self._s.cookies while 5+ worker/HTTP threads read self._s unlocked.

Activity

  1. self-assigned this
    on Dec 2, 2026
  2. added
    bug
    on Dec 2, 2026
  3. mlgitdev commented on Dec 2, 2026

    @mlgitdev
    OwnerAuthor

    🚀 Resolution In Progress

    A fix for this issue has been implemented and submitted in Pull Request #82 (v2.12.1).

    This issue will automatically close upon PR #82 review and merge into main.

  4. github-actions commented on Dec 2, 2026

    @github-actions

    ✅ Issue Validation Passed

    • Conventional Commit title syntax (fix(tv))
    • Verified issue type: BUG
    • Required template sections present and filled out

    This issue is well-structured and ready for work according to the Issue-First Protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions