lostisland / lostisland/faraday

Refactor: Connection Pooling

Open
#1,024 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.9k
Forks
1k
Avg merge
5d 17h
Merged PRs (30d)
6

Description

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 https://github.com/lostisland/faraday/pull/1006#issuecomment-533371062.

## TODO

* [x] Add `#build_connection` to every adapter, which outputs the fully-configured http client from options. #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???

https://github.com/lostisland/faraday/blob/ba7b82d9a2211c4fdd840189e246dbd7a6e4c229/lib/faraday/connection.rb#L493-L497

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the unchecked TODO items and the discussion in pull request #1006, then inspect the proxy-handling code linked in lib/faraday/connection.rb. Trace the completed #build_connection work in #1023 and the adapter paths it affects. Done means implementing and validating the remaining connection-option, pooling, initialization, and connection-yielding behavior, including the proxy question.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.