Log a failed session exchange instead of reporting a lost connection
FA
3h ago+50+50+01234567890123456789-2-2-0123456789
Why
If a reverse proxy does not forward /_reflex/session, the session cookie exchange fails while the WebSocket works. The failure went into connectErrors, so the page showed this toast for as long as the exchange failed:
Cannot connect to server: Session request failed: 405. Check if server is reachable at ws://localhost:8000/_event
The toast points at the WebSocket, which works, and hides the real cause. I found this while I tested the enforced session default of #7364 with an app behind a proxy that does not route /_reflex/session.
What changed
- An exchange failure other than 403 is logged to the browser console, once per streak of failures, with the route to check. A 403 is already logged this way.
- The retry with backoff does not change. Uploads still stop waiting for the exchange after three failures.
- A successful exchange no longer clears
connectErrors, because the exchange no longer adds to them. The socket's connect handler clears them.
How tested
- Regression test first (1c56187c2) in
tests/state_connection.test.js. It mounts the event loop, answers two exchanges with a 405, and checks thatconnectErrorsstays empty and thatconsole.errorgets the complete message once. Before the fix,connectErrorsheld both errors. npm run checkinpackages/reflex-frontendpasses: lint, JSDoc types, and 219 tests.- I saw the toast above in Chromium before the fix. I did not run the app again after the fix.
Known limits
- When the exchange keeps failing, the page itself shows nothing. Only an upload shows an error (the 403 toast). The console message is for the person who deploys the app.
- #7364 adds
docs/api-routes/sessions.md. When both PRs are merged, its paragraph about an exchange that keeps failing can mention the console message.
Type of change
- Bug fix (non-breaking change which fixes an issue)