ruby / ruby/net-http

Feature Request: Tracking # of HTTP requests made on the current TCP connection

Open
#266 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
148
Forks
95
Avg merge
10h 54m
Merged PRs (30d)
4

Description

For persistent connections, some servers are configured to reset them after a certain number of HTTP requests. Net::HTTP::Persistent added a max_requests variable to preemptively close your connection after a certain amount of HTTP requests are made for this reason in https://github.com/drbrain/net-http-persistent/pull/42

However, without changes to Net::HTTP, Net::HTTP::Persistent can only track how many times it makes a request of it's Net::HTTP instance. But this isn't perfect: begin_transport can re-connect on a new TCP connection if it finds the socket was closed some time after the last time you used it, like if the server closed the connection, and Net::HTTP::Persistent will never know there's a new TCP connection, and that it should therefor reset its count of requests over the TCP connection back to 0.

My suggestion is that we make an instance variable here in Net::HTTP called @num_requests_on_connection, that gets set to 0 at the end of connect, and is incremented at the end of begin_transport after the reconnection attempts. I believe that way we could get an accurate count!

@raggi @drbrain

Contributor guide

No contributing guide indexed for this repository

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 in lib/net/http.rb at the referenced connect and begin_transport locations, and trace how persistent connections are established and reused. Verify the request count resets when a TCP connection is created and increments after transport attempts, so callers can accurately observe requests made on the current connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.