Skip to content
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

Configurable client requests timeout #501

Open
carlosperate opened this issue Dec 16, 2024 · 3 comments
Open

Configurable client requests timeout #501

carlosperate opened this issue Dec 16, 2024 · 3 comments

Comments

@carlosperate
Copy link

carlosperate commented Dec 16, 2024

Similar to this issue, but not quite the same, as it's in a different part of the project:

Essentially when doing a large number of async request I'm seeing a lot of timeouts and increasing the httpx default timeout (via the httpx timeout constructor parameter) resolves it:

self._client = httpx.AsyncClient(follow_redirects=True)

Would it be possible to provide a user-configurable timeout parameter atproto.Client/AsynClient as well, that is passed to httpx?

@MarshalX
Copy link
Owner

MarshalX commented Dec 16, 2024

Idk it is the best way to do so. There are plenty of configuration options. At least three were asked already: retry policy, proxy, and timeout. And for now, the best way to configure it is to make a simple inherit from the class. Like this: #467 (comment)

@nlurker
Copy link

nlurker commented Dec 16, 2024

Are you talking about InvokeTimeoutError? I get that a lot.

@carlosperate
Copy link
Author

Are you talking about InvokeTimeoutError? I get that a lot.

Yes, this is the exception that bubbles up when httpx times out.

Idk it is the best way to do so. There are plenty of configuration options. At least three were asked already: retry policy, proxy, and timeout. And for now, the best way to configure it is to make a simple inherit from the class. Like this: #467 (comment)

That sounds good, as long as it is easy to inherit from AsyncRequest, for example something like this:

import asyncio
import httpx
from atproto import AsyncClient
from atproto_client.request import AsyncRequest

class CustomAsyncRequest(AsyncRequest):
    def __init__(self) -> None:
        super().__init__()
        # Here just customise whatever the user needs
        self._client = httpx.AsyncClient(follow_redirects=True, timeout=10.0)

async def foo():
    client = AsyncClient(request=CustomAsyncRequest())
    ...

asyncio.run(foo())

Alternatively, if all the configuration needed was in the httpx client, we could just pass one as a AsyncRequest constructor argument:

import asyncio
import httpx
from atproto import AsyncClient


async def foo():
    custom_client = httpx.AsyncClient(follow_redirects=True, timeout=10.0)
    client = AsyncClient(client=custom_client)
    ...

asyncio.run(foo())

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

No branches or pull requests

3 participants