feat: add shared HTTP sessions and configurable timeouts - #258
Merged
Conversation
Co-authored-by: Matthew Spah <[email protected]>
Mattsface
marked this pull request as ready for review
August 1, 2026 05:49
Mattsface
commented
Aug 1, 2026
Mattsface
left a comment
Member
Author
There was a problem hiding this comment.
Looks good. thumbs up
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.
Why a shared session
Module-level
requests.get()prevented connection reuse and made timeouts, session injection, and cleanup difficult. This change introduces one reusablerequests.SessionperMlbclient so HTTP connections can be pooled and request behavior can be configured without changing endpoint APIs.How v1 and v1.1 share one session
Mlbcreates or accepts exactly one session, then injects that same instance into both adapters:Adapters that receive an injected session do not own it and will not close it.
Default timeout and overrides
Default timeout:
Every adapter request passes
timeout=explicitly. Supported forms include:The same forms are accepted by
MlbDataAdapter.Ownership rule
Sharing and ownership are separate: both adapters share the session, but neither owns a session injected by
Mlb.Cleanup and context manager
Mlb.close()andMlbDataAdapter.close()close library-owned sessions at most once and are safe to call repeatedly.with Mlb() as mlb:returns the client from__enter__and callsclose()from__exit__, including when the block exits due to an exception. Exceptions are not suppressed.Compatibility
Existing positional constructors remain valid:
Unchanged behavior
MlbResultbehaviorIntentionally not included
Retry-AfterTests
Live MLB adapter tests succeeded; no external outage observed.