From 7b523fe9bd236749c4afaf16dc1895adeab73850 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Wed, 16 Apr 2025 07:42:30 -0700 Subject: [PATCH 1/3] changes --- client/python/gradio_client/client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/python/gradio_client/client.py b/client/python/gradio_client/client.py index 55f29cbf37..7536bef91e 100644 --- a/client/python/gradio_client/client.py +++ b/client/python/gradio_client/client.py @@ -887,6 +887,15 @@ def _get_config(self) -> dict: **self.httpx_kwargs, ) if r.is_success: + # Cookies are sometimes needed to correctly route requests using + # multiple replicas e.g. using cookie session-affinity in Kubernetes. + # This approach attaches cookies to subsequent requests (without overriding existing cookies) + new_cookies = { + name: value + for name, value in r.cookies.items() + if value is not None and name not in self.cookies + } + self.cookies.update(new_cookies) return r.json() elif r.status_code == 401: raise AuthenticationError( From f5e42fa1c0303626ffa31c9b2de5558e6eb2385e Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 16 Apr 2025 14:47:43 +0000 Subject: [PATCH 2/3] add changeset --- .changeset/easy-doodles-sip.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/easy-doodles-sip.md diff --git a/.changeset/easy-doodles-sip.md b/.changeset/easy-doodles-sip.md new file mode 100644 index 0000000000..2be6953ce2 --- /dev/null +++ b/.changeset/easy-doodles-sip.md @@ -0,0 +1,6 @@ +--- +"gradio": patch +"gradio_client": patch +--- + +fix:Attach cookies to client after first request (to support multiple-replica setups with cookie-based affinity) From 8f4b238d2d37bb1aab95669d269ad02bcc3f16e8 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Wed, 16 Apr 2025 11:36:18 -0700 Subject: [PATCH 3/3] clear --- client/python/gradio_client/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/python/gradio_client/client.py b/client/python/gradio_client/client.py index 7536bef91e..508c786d6d 100644 --- a/client/python/gradio_client/client.py +++ b/client/python/gradio_client/client.py @@ -887,9 +887,10 @@ def _get_config(self) -> dict: **self.httpx_kwargs, ) if r.is_success: - # Cookies are sometimes needed to correctly route requests using - # multiple replicas e.g. using cookie session-affinity in Kubernetes. - # This approach attaches cookies to subsequent requests (without overriding existing cookies) + # Cookies are sometimes needed to correctly route requests if the Gradio app is + # running on multiple replicas e.g. using cookie session-affinity in Kubernetes. + # This approach attaches cookies from the first response to subsequent requests + # without overriding existing cookies. new_cookies = { name: value for name, value in r.cookies.items()