You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Tracking # of HTTP requests made on the current TCP connection #266
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 drbrain/net-http-persistent#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.
Would be happy to send in a PR with tests if maintainers could comment that they would accept one!
(For context, my service is hitting a frequently overloaded 3rd party API server, and doing what we can from our end to minimize the number of the connections to it we need has already improved the situation greatly, and would love to get this optimized as well. Getting the 3rd party to increase the resources or tune their connection settings is unfortunately not an option)
I'd love to be able to track the age of the connection in a similar way as well. Some servers let you specify a max age for a TCP socket, not just an idle keepalive time, and would love to be able to see if we are hitting that in logs. Again, happy to do the PR myself if it would be accepted!
Activity
mohamedhafez commentedon Dec 29, 2025
Would be happy to send in a PR with tests if maintainers could comment that they would accept one!
(For context, my service is hitting a frequently overloaded 3rd party API server, and doing what we can from our end to minimize the number of the connections to it we need has already improved the situation greatly, and would love to get this optimized as well. Getting the 3rd party to increase the resources or tune their connection settings is unfortunately not an option)
mohamedhafez commentedon Dec 29, 2025
I'd love to be able to track the age of the connection in a similar way as well. Some servers let you specify a max age for a TCP socket, not just an idle keepalive time, and would love to be able to see if we are hitting that in logs. Again, happy to do the PR myself if it would be accepted!