Skip to content

Refactor: Connection Pooling #1024

Description

@technoweenie

This is a tracking issue for a larger effort to refactor the adapters to support connection pools. #1006 proved it could work in theory, but I think the code bass will need some more massaging to fully support it. I outlined why in #1006 (comment).

TODO

  • Add #build_connection to every adapter, which outputs the fully-configured http client from options. Cleanup adapter connections #1023
  • Send ConnectionOptions to Env as :connection key.
  • Copy settings that configure the HTTP connection from RequestOptions to ConnectionOptions: :proxy, :bind, :timeout, :read_timeout, :open_timeout, :write_timeout
  • Teach Adapter#build_connection to merge ConnectionOptions with RequestOptions.
  • Remove manual merging of :proxy into RequestOptions
  • Teach Adapter#initialize to save the connection if it can:
    • If any of the moved RequestOptions settings are used, skip this!
    • If the adapter supports pooling, @pool = ConnectionPool.new(opts, &method(:build_connection))
    • If the adapter does not support pooling, @conn = build_connection
  • Add connection(&block) to yield a connection for the adapter to use:
    • If any of the moved RequestOptions settings are used, yield #build_connection)
    • If the adapter supports pooling, pass block to @pool.with
    • If the adapter does not support pooling, yield @conn

Proxy options???

# Resets temp_proxy
@temp_proxy = proxy_for_request(url)
request = build_request(method) do |req|
req.options = req.options.merge(proxy: @temp_proxy)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions