connect-sdk-python icon indicating copy to clipboard operation
connect-sdk-python copied to clipboard

[Feat] Allow custom timeout using env vars

Open raphapassini opened this issue 1 year ago • 1 comments

For some use cases, for instance, when there's a VPN between the computer running the client and the 1password servers the default timeout may not be enough. In those cases the user receives a httpx.ConnectTimeout exception.

This PR will allow the user to define a custom timeout by using an environment variable.

raphapassini avatar Feb 01 '24 22:02 raphapassini

@volodymyrZotov quick one, do you mind taking a look. This is really important for us as we're seeing lots of timeouts here

HaddadJoe avatar Mar 20 '24 17:03 HaddadJoe

Hey @volodymyrZotov thanks for the review. I've done the requested changes. Do you mind doing another review? Thanks :)

raphapassini avatar Mar 28 '24 17:03 raphapassini

nice thanks! any eta on the next release please?

HaddadJoe avatar Apr 02 '24 15:04 HaddadJoe

@HaddadJoe will be available later today or tomorrow

volodymyrZotov avatar Apr 02 '24 15:04 volodymyrZotov

@volodymyrZotov I think this PR is causing issues. If it's not set the int here sets timeout to 0. The if statement fails because 0 as boolean is false. It then defaults to USE_CLIENT_DEFAULT which is a class. Or when you call that underlying https library does some addition

File "/pypoetry/virtualenvs/Av-py3.11/lib/python3.11/site-packages/anyio/_core/_tasks.py", line 111, in fail_after deadline = (current_time() + delay) if delay is not None else math.inf ~~~~~~~~~~~~~~~^~~~~~~ TypeError: unsupported operand type(s) for +: 'float' and 'UseClientDefault'

def get_timeout() -> Union[int, UseClientDefault]:
    """Get the timeout to be used in the HTTP Client"""
    timeout = int(os.getenv(ENV_CLIENT_REQUEST_TIMEOUT, 0))
    return timeout if timeout else USE_CLIENT_DEFAULT

as a fix for now, using the timeout works fine but the default scenario, which will be most 1pass users as of now it will fail

HaddadJoe avatar Apr 02 '24 21:04 HaddadJoe

@HaddadJoe Thank you for letting know! It needs a fix.

volodymyrZotov avatar Apr 02 '24 22:04 volodymyrZotov

Hi team, since this PR was merged, our deployment of the 1Password Connect Server is failing although we have updated our deployment with the new environment variable where the SDK is running: OP_CLIENT_REQUEST_TIMEOUT=90.

The error message is

TypeError: 'UseClientDefault' object cannot be interpreted as an integer

Can you advise on how we can fix this issue please?

tblnd avatar Apr 03 '24 08:04 tblnd

@tblnd until a fix is released what worked for us is setting OP_CONNECT_CLIENT_REQ_TIMEOUT to something reasonable like 5 or 10 (it's in seconds)

HaddadJoe avatar Apr 03 '24 09:04 HaddadJoe

I've created a PR that should fix the issue

raphapassini avatar Apr 03 '24 12:04 raphapassini

Fixed in v1.5.1

volodymyrZotov avatar Apr 03 '24 18:04 volodymyrZotov