aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

Allow changing connector limit on runtime

Open siddhpant opened this issue 5 months ago • 2 comments

Is your feature request related to a problem?

I want to reduce my connection limit on getting rate-limited.

A web server can decide to rate-limit number of connections out of the blue.

Describe the solution you'd like

Allow changing Session.connector.limit.

Describe alternatives you've considered

  • Enforcing limit manually in a subclass.
  • Changing Session.connector._limit.

Both can be avoided if the functionality is provided directly.

Related component

Client

Additional context

No response

Code of Conduct

  • [x] I agree to follow the aio-libs Code of Conduct

siddhpant avatar Jul 28 '25 08:07 siddhpant

Hi, I’d like to take this up and open a PR. The plan is to add a safe, public way to change Session.connector.limit at runtime, so users don’t need to rely on private attributes or subclassing. If there are any design preferences (e.g., method naming, exposure via ClientSession vs. connector), please let me know before I start. Thanks!

kingsmen732 avatar Aug 24 '25 20:08 kingsmen732

Is your usecase the same as above? I'm kind of struggling to see how this would be generally useful. The original issue mentions rate limiting, but in the vast majority of cases this would be a limit on the frequency of requests, not a limit on the number of simultaneous connections. There are better solutions for rate limiting.

Dreamsorcerer avatar Aug 24 '25 21:08 Dreamsorcerer