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

Chainlit Copilot failures when behind a LB with cookie based sticky sessions #1279

Open
mattgartman opened this issue Aug 30, 2024 · 1 comment

Comments

@mattgartman
Copy link

Describe the bug
Chainlit requires sticky sessions when hosted behind a cluster. Many Kubernetes Ingress solutions leverage cookies for sticky sessions.

When leveraging Chainlit's Copilot feature, cookies are not sent along during the initial setup of the websocket causing the Copilot widget to fail with an error of Could not reach the server..

When inspecting the network track you will see POSTs being sent to https://{chainlit_server_url}/ws/socket.io/?EIO=4&transport=polling&t={##}&sid={##} and receiving a http 400 BAD REQUEST with the response being Invalid session {###}. Response from the server can be seen using Set-Cookie however requests being made from the Copilot code do not send the cookie.

While using Chainlit's UI directly everything works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. Run a Chainlit application in a Kubernetes deployment with multiple replicas
    1. Enable Ingress with cookie based sticky sessions
  2. Configure a second site to load Chainlit Copilot

Expected behavior
When the Chainlit Copilot widget reaches out to the Chainlit server it should pass cookies that have been set in the session.

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Windows and MacOS
  • Browser: All (observed on Edge and Chrome)
  • Version: n/a

Smartphone (please complete the following information):
n/a

Additional context

Consider using withCredentials to resolve this issue.

@ShubhamMaddhashiya-bidgely

Hi, is there any update on this issue? I'm experiencing the same problem where cookies are not being set in the request headers.

Upon investigation, I found that after enabling cookies, we also need to set withCredentials: true in the Socket.IO client configuration to include cookies in the request headers.

Reference: https://socket.io/how-to/deal-with-cookies

Starting with version 4.7.0, when setting the withCredentials option to true, the Node.js client will now include the cookies in the HTTP requests, making it easier to use it with cookie-based sticky sessions.

In Chainlit's react-client code, it appears that the withCredentials: true parameter is missing in the Socket.IO client setup: useChatSession.ts#L103. Adding this might resolve the issue for cookie-based sticky sessions.

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

No branches or pull requests

2 participants