refactor(flaresolverr): replace module-global state with a configured client - #167
Merged
Conversation
… client The bypass URL was a module-level global reassigned via set_flaresolverr_url() on every Init(), with a module-level session alongside it, so the configuration lived in mutable global state rather than being owned by anything. FlareSolverr is now a small class holding its own URL and session. Torchlight builds one from config (falling back to the previous default when no FlareSolverr section is present) and FFmpegAudioPlayer reaches it through self.torchlight. Init() runs again on every reconnect, which previously did not matter because the session was global; now that each Torchlight owns one, Init() closes the outgoing instance's session before replacing it so reconnects do not leak sessions. Bumps VERSION to 1.8.20. Closes #159 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Dolly132 <109222243+Dolly132@users.noreply.github.com>
Rushaway
commented
Sep 5, 2026
Rushaway
left a comment
Member
Author
There was a problem hiding this comment.
Self-review: the non-obvious part is that moving the session off the module global introduces a per-reconnect leak unless Init() closes the outgoing one -- Init() runs on every OnDisconnect, so that would have quietly accumulated aiohttp sessions on a flappy SMAPI link. Handled it explicitly and verified session reuse still works so #144's pooling benefit isn't lost. @Dolly132 this touches the close_cf_session wiring you added in #144, so worth your eyes specifically.
Dolly132
added a commit
to Dolly132/torchlight
that referenced
this pull request
Sep 6, 2026
Dolly132
approved these changes
Sep 6, 2026
Dolly132
left a comment
Collaborator
There was a problem hiding this comment.
Tested, works fine as intended.
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.
Summary
set_flaresolverr_url()on everyInit(), with a module-level session next to it — configuration living in mutable global state rather than owned by anything.FlareSolverris now a small class holding its own URL and session.Torchlightbuilds one from config (falling back to the previoushttp://127.0.0.1:8191/v1default when there's noFlareSolverrsection), andFFmpegAudioPlayerreaches it viaself.torchlight.flaresolverr.A leak this surfaced
Init()re-runs on every reconnect (OnDisconnect→Init()). That didn't matter while the session was global — it was reused across re-inits. Now that eachTorchlightowns one, a naive port would leak an aiohttp session per reconnect. SoInit()now closes the outgoing instance's session before replacing it, and__del__closes the current one (guarded withgetattr, since__del__can run before/after attributes exist).Closes #159
Test plan
Against a live local stub of the FlareSolverr API:
http://10.0.0.5:9999/v1.FlareSolverrconfig section → falls back to the previous default, unchanged.get_cf_sessionreturns the parsed cookies/user-agent and reuses the same session across calls (the pooling win from fix(flaresolverr): reuses a pooled session instead of opening one per call #144 is preserved).close()closes the session and clears the reference.set_flaresolverr_url/close_cf_session; all modules compile.🤖 Generated with Claude Code