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

gradio_client only forwards cookies when using auth #10164

Open
1 task done
danbgoldman opened this issue Dec 10, 2024 · 4 comments
Open
1 task done

gradio_client only forwards cookies when using auth #10164

danbgoldman opened this issue Dec 10, 2024 · 4 comments
Labels
bug Something isn't working gradio_client Related to the one of the gradio client libraries

Comments

@danbgoldman
Copy link

Describe the bug

The python gradio_client library does not cache any server cookies unless the Client constructor is called with password authentication via auth argument. (You can see this by inspecting the code: The Client.cookies member is only set in one place, on this line, inside the _login method.)

However, cookies are not only used for authentication. They are also needed in other scenarios - such as, properly routing requests when using multiple replicas of a service in Kubernetes. (The documentation mentions using sessionAffinity, but this doesn't work with ingress, as explained here.)

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

This bug is reproducible with any demo running in multiple replicas in Kubernetes, when called using the client API. But it's a bit tricky to provide a minimal example here, because it would include docker containers, k8s yamls and all kinds of other things that have nothing to do with gradio.

Screenshot

No response

Logs

No response

System Info

I've reproduced this bug mostly with gradio 4.43.0 but it also seems to still be present in the latest version (5.8.0) as seen on GitHub.

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 4.44.1
gradio_client version: 1.3.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.6.2.post1
fastapi: 0.115.4
ffmpy: 0.4.0
gradio-client==1.3.0 is not installed.
httpx: 0.27.2
huggingface-hub: 0.26.2
importlib-resources: 6.4.5
jinja2: 3.1.2
markupsafe: 2.1.1
matplotlib: 3.4.2
numpy: 1.21.1
orjson: 3.10.11
packaging: 21.3
pandas: 1.3.5
pillow: 10.2.0
pydantic: 2.9.2
pydub: 0.25.1
python-multipart: 0.0.17
pyyaml: 6.0
ruff: 0.7.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.5
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.32.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.10.0
httpx: 0.27.2
huggingface-hub: 0.26.2
packaging: 21.3
typing-extensions: 4.12.2
websockets: 12.0

Severity

I can work around it

@danbgoldman danbgoldman added the bug Something isn't working label Dec 10, 2024
@abidlabs
Copy link
Member

Thanks @danbgoldman would you like to open a PR for a fix for this? Happy to review

@abidlabs abidlabs added the gradio_client Related to the one of the gradio client libraries label Dec 10, 2024
@danbgoldman
Copy link
Author

I'm not sure the best way to fix this.

  1. The easy solution is just to make an arbitrary GET / request to initialize the cookies. But that introduces unnecessary network overhead.
  2. The network-friendly solution would be to lazily initialize the cookies on the first (or every) returned response. But that would require refactoring all the httpx calls.

Is there a URL to query that will just return a short response with headers? I see heartbeat, but I don't want a streaming response, just an "alive" message.

@abidlabs
Copy link
Member

Hi @danbgoldman could we do this as part of _get_config()? This gets called once when the Client is initiated. We could append any cookies that are returned to self.cookies

@danbgoldman
Copy link
Author

Yes I think so. (I am waiting on my employer's approval to make open-source contributions. This may not happen until after the holidays.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gradio_client Related to the one of the gradio client libraries
Projects
None yet
Development

No branches or pull requests

2 participants