Skip to content

Improve memory usage and client robustness#30

Open
tomas wants to merge 31 commits into
masterfrom
cap-memory-usage
Open

Improve memory usage and client robustness#30
tomas wants to merge 31 commits into
masterfrom
cap-memory-usage

Conversation

@tomas

@tomas tomas commented Apr 17, 2026

Copy link
Copy Markdown
Member

Potential memory leaks:

  • Entity and Relation now hold a WeakRef to the client/strategy, so entity graphs retained by application code (caches, sessions) no longer prevent the Strategy, its Faraday connection pool, and auth credentials from being garbage collected. A clear RuntimeError is raised if a link is followed after the strategy has been GC'd.
  • Configuration#logger now memoises with ||= instead of ||, preventing a fresh Logger from being allocated on every call when no logger is set.
  • Strategy no longer allocates an empty Proc.new{} when no on_new_token block is given; on_new_token is nil and callers use &.call.

Code improvements:

  • Oauth2Strategy#retryable: remove redundant begin/end wrapper.
  • Replace default Faraday::HttpCache::MemoryStore (unbounded) with BoundedMemoryStore, which evicts the oldest entry once the cache reaches 500 entries, capping in-process memory growth in long-running servers.

New features:

  • Client#close: nilifies the memoised Faraday connection so it can be GC'd.
  • Client accepts :timeout and :open_timeout options and forwards them to Faraday, making request timeouts configurable without monkey-patching.
  • TooManyRequestsError (HTTP 429) added to the error hierarchy so callers can rescue rate-limit responses distinctly from other transport

tomas added 30 commits April 28, 2020 18:22
…ies on requested instead of on initialization
Potential memory leaks:
- Entity and Relation now hold a WeakRef to the client/strategy, so
  entity graphs retained by application code (caches, sessions) no longer
  prevent the Strategy, its Faraday connection pool, and auth credentials
  from being garbage collected. A clear RuntimeError is raised if a link
  is followed after the strategy has been GC'd.
- Configuration#logger now memoises with ||= instead of ||, preventing a
  fresh Logger from being allocated on every call when no logger is set.
- Strategy no longer allocates an empty Proc.new{} when no on_new_token
  block is given; on_new_token is nil and callers use &.call.

Code improvements:
- Oauth2Strategy#retryable: remove redundant begin/end wrapper.
- Replace default Faraday::HttpCache::MemoryStore (unbounded) with
  BoundedMemoryStore, which evicts the oldest entry once the cache reaches
  500 entries, capping in-process memory growth in long-running servers.

New features:
- Client#close: nilifies the memoised Faraday connection so it can be GC'd.
- Client accepts :timeout and :open_timeout options and forwards them to
  Faraday, making request timeouts configurable without monkey-patching.
- TooManyRequestsError (HTTP 429) added to the error hierarchy so callers
  can rescue rate-limit responses distinctly from other transport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant