Skip to content

Httpx timeout improvements #4882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 31, 2025
Merged

Httpx timeout improvements #4882

merged 13 commits into from
Jul 31, 2025

Conversation

Poolitzer
Copy link
Member

As discussed, we think its appropriate to change the default timeout and drop the max_keepalive_connections

Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double check the implementations of (Ext)Bot and ApplicationBuilder. I'm pretty sure that the arguments to HTTPXRequest need adaption for the get_updates_request instances and some docstrings might need updating as well. This will probably also fix the failing tests.

@@ -0,0 +1,5 @@
other = "Httpx timeout improvements"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please give a short explanation of the change here and explain what users need to change if they manually build HTTPXRequest objects.

@Poolitzer
Copy link
Member Author

Poolitzer commented Jul 27, 2025

Please double check the implementations of (Ext)Bot and ApplicationBuilder. I'm pretty sure that the arguments to HTTPXRequest need adaption for the get_updates_request instances

I thought about this, but came to the conclusion that that shouldn't be needed. They set the connection to 1, as expected, and since there is just one connection in the pool, it shouldn't matter that max_keepalive_connections is set to 20 now, since well. There is only one over all :D

@@ -0,0 +1,5 @@
other = "Default httpx max_connections/pool size set to 256, and dropping setting max_keepalive_connections to the same amount. If you manually build the httpx request, be aware that this also applies to you. If you want your own limits, you can set them via httpx_kwargs, as explained in https://www.python-httpx.org/advanced/resource-limits/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to mention the motivation behind the change too?

@Bibo-Joshi
Copy link
Member

Please double check the implementations of (Ext)Bot and ApplicationBuilder. I'm pretty sure that the arguments to HTTPXRequest need adaption for the get_updates_request instances

I thought about this, but came to the conclusion that that shouldn't be needed. They set the connection to 1, as expected, and since there is just one connection in the pool, it shouldn't matter that max_keepalive_connections is set to 20 now, since well. There is only one over all :D

self._request: tuple[BaseRequest, BaseRequest] = (
HTTPXRequest() if get_updates_request is None else get_updates_request,
HTTPXRequest() if request is None else request,
)

Here in line 342 I expect the connection pool to be 1 for the get_updates request instance

if get_updates:
connection_pool_size = (
DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 1
)
else:
connection_pool_size = (
DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) or 256
)

Here in line 256 we duplicate the default value 256. We could try to avoid that by not passing connection_pool_size in case DefaultValue.get_value(getattr(self, f"{prefix}connection_pool_size")) is None, though that may be unnecessary complication …

@harshil21 harshil21 added the 🛠 refactor change type: refactor label Jul 29, 2025
Poolitzer and others added 3 commits July 31, 2025 20:22
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
my bad, pool, mea culpa :D
@Bibo-Joshi Bibo-Joshi merged commit 197f29b into master Jul 31, 2025
31 checks passed
@Bibo-Joshi Bibo-Joshi deleted the httpx_timeout_improvements branch July 31, 2025 18:54
@Bibo-Joshi
Copy link
Member

Thank you for your patience ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠 refactor change type: refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy