503 HTTP Response on OpenID Authentication when running multiple instances of API #7452
-
What happened?This is an interesting bug that I found when integrated with OpenID. I found that when I tested locally, everything worked great, but then in our test environment, I would see HTTP 503 responses when handling the callback. This is a "transient" bug in the fact that if your load balancer sends you to a different instance in the callback from the originating instance, you will see this bug. If the originating instance and the callback instance are the same, you won't see this bug. Version InformationGit Commit hash -> This bug was found using the packaged docker instance -> Setup to reproduce locallyIn your
Create a
Lastly, you should setup an OpenID authentication according to the documentation -> https://www.librechat.ai/docs/configuration/authentication/OAuth2-OIDC At this point, you can follow the steps to reproduce below. Steps to Reproduce
Expected ActionYour authentication is completed and you arrrive at the Actual ResponseYou get the page with WorkaroundsThere are several work arounds:
What browsers are you seeing the problem on?No response Relevant log outputBelow are the logs from the steps to reproduce with the load balancer setup.
----------------------------------------------------------------------------
chat-nginx | 192.168.65.1 - - [19/May/2025:14:46:15 +0000] "GET /login HTTP/1.1" 200 1102 "http://localhost:3080/login" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
api-1 | {"level":"debug","message":"X-Forwarded headers detected in OAuth request:","timestamp":"2025-05-19T14:46:16.699Z","x-forwarded-for":"192.168.65.1","x-forwarded-proto":"http"}
chat-nginx | 192.168.65.1 - - [19/May/2025:14:46:16 +0000] "GET /oauth/openid HTTP/1.1" 302 0 "http://localhost:3080/login" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
chat-nginx | 192.168.65.1 - - [19/May/2025:14:46:17 +0000] "GET /sw.js HTTP/1.1" 304 0 "http://localhost:3080/sw.js" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
f,"timestamp":"2025-05-19T14:46:17.376Z","x-forwarded-for":"192.168.65.1","x-forwarded-proto":"http"}
chat-nginx | 192.168.65.1 - - [19/May/2025:14:46:17 +0000] "GET /oauth/openid/callback?code=XXXX&state=XXX HTTP/1.1" 500 148 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
api-2 | Error: did not find expected authorization request details in session, req.session["oidc:xxx.okta.com"] is undefined
api-2 | at /app/node_modules/openid-client/lib/passport_strategy.js:132:13
api-2 | at OpenIDConnectStrategy.authenticate (/app/node_modules/openid-client/lib/passport_strategy.js:191:5)
api-2 | at attempt (/app/node_modules/passport/lib/middleware/authenticate.js:369:16)
api-2 | at authenticate (/app/node_modules/passport/lib/middleware/authenticate.js:370:7)
api-2 | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
api-2 | at next (/app/node_modules/express/lib/router/route.js:149:13)
api-2 | at Route.dispatch (/app/node_modules/express/lib/router/route.js:119:3)
api-2 | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
api-2 | at /app/node_modules/express/lib/router/index.js:284:15
api-2 | at Function.process_params (/app/node_modules/express/lib/router/index.js:346:12) ScreenshotsNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is not a bug in the LibreChat codebase itself, but rather an expected behavior when using session-based authentication in a distributed environment without proper session management. What you're experiencing is a common challenge in horizontally scaled applications:
This is a fundamental architectural consideration rather than a code defect. In distributed systems with stateful authentication flows, you need one of the following:
The LibreChat application includes Redis for session storage, which should be properly configured in production environments with multiple instances. The default Docker setup uses in-memory session storage which works correctly for single-instance deployments. I recommend configuring Redis session storage for your multi-instance deployment as documented here: LibreChat Redis Configuration |
Beta Was this translation helpful? Give feedback.
This is not a bug in the LibreChat codebase itself, but rather an expected behavior when using session-based authentication in a distributed environment without proper session management.
What you're experiencing is a common challenge in horizontally scaled applications:
This is a fundamental architectural consideration rather than a code defect. In distributed systems with stateful authentication flows, you need one of the following: