Ussue Description
- Error only shows up the next day when you reopen the browser, and it clears up after you sign out and back in.
- Chainlit UI expires every day but not Microsoft authentication. When error happens i have to signout from chainlit UI then it takes me to /auth page where i take token from Microsoft External Entra and then sign back in.
Error Message
Error: peer closed connection without sending complete message body (incomplete chunked read)
Likely Causes:
Expired session tokens :
- apps store an access token in local storage or cookies. Overnight, that token may expire. When the client tries to resume a streaming request with an invalid token, the server often just closes the connection instead of sending a clean JSON error — which surfaces as the “peer closed connection without sending complete message body” error.
Stale cookies or cached state:
- If the browser restores the app tab from the previous day, the client may try to reuse an old connection or cached auth state that the server no longer accepts.
Why signing out/in fixes it
-
Signing out clears the stale token/cookies.
-
Signing back in forces a fresh token exchange, so subsequent requests succeed and the server no longer drops the connection.
Files to refer:
https://github.com/PrynAI/PrynAI-chat/tree/main/apps/chainlit-ui/src/auth
https://github.com/PrynAI/PrynAI-chat/tree/main/apps/gateway-fastapi/src/auth
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/public/login-redirect.js
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/main.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/server.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/threads_client.py
Potential Fixes:
Implement token refresh:
- Store both access and refresh tokens securely.
- Before each API call, check expiry and refresh if needed.
- Or use a library that handles this automatically (MSAL for Python/JS).
Bootstrap check: On app load, validate the token. If expired, refresh immediately instead of waiting for the first API call to fail.
Ussue Description
Error Message
Error: peer closed connection without sending complete message body (incomplete chunked read)
Likely Causes:
Expired session tokens :
Stale cookies or cached state:
Why signing out/in fixes it
Signing out clears the stale token/cookies.
Signing back in forces a fresh token exchange, so subsequent requests succeed and the server no longer drops the connection.
Files to refer:
https://github.com/PrynAI/PrynAI-chat/tree/main/apps/chainlit-ui/src/auth
https://github.com/PrynAI/PrynAI-chat/tree/main/apps/gateway-fastapi/src/auth
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/public/login-redirect.js
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/main.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/server.py
https://github.com/PrynAI/PrynAI-chat/blob/main/apps/chainlit-ui/src/threads_client.py
Potential Fixes:
Implement token refresh:
Bootstrap check: On app load, validate the token. If expired, refresh immediately instead of waiting for the first API call to fail.