Skip to content

Log a failed session exchange instead of reporting a lost connection - #8061

Open
FarhanAliRaza wants to merge 3 commits into
mainfrom
farhan/session-exchange-error-console
Open

FarhanAliRaza wants to merge 3 commits into
mainfrom
farhan/session-exchange-error-console

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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 (1c56187) in tests/state_connection.test.js. It mounts the event loop, answers two exchanges with a 405, and checks that connectErrors stays empty and that console.error gets the complete message once. Before the fix, connectErrors held both errors.
  • npm run check in packages/reflex-frontend passes: 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.
  • Validate enforced sessions and document migration #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)

View guided diff Turn on auto-fix

A reverse proxy that does not forward /_reflex/session answers the cookie
exchange with an error while the WebSocket works. The event loop adds that
error to connectErrors, so the connection toast reports that the server
cannot be reached at the WebSocket URL. This test fails until the failure
is logged instead.
A failed cookie exchange went into connectErrors, which drives the
connection toast and banner. The WebSocket still works in that case, so
the toast pointed at the wrong cause: "Cannot connect to server ... Check
if server is reachable at ws://.../_event". A 403 from the exchange was
already logged to the console. Log every other failure the same way, once
per streak of failures, and name the route to check. The retry with
backoff is unchanged. The success path no longer clears connectErrors,
because the exchange no longer adds to it; the socket's connect handler
clears them.
@FarhanAliRaza
FarhanAliRaza requested a review from a team as a code owner November 30, 2026 10:30
@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Nov 30, 2026 — with ChatGPT Codex Connector
@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable issues were found.

Summary

Session exchange failures now go to the browser console instead of connectErrors.

  • Failed session exchanges no longer look like WebSocket outages.

Reviews (2) · Last reviewed commit: "Test that a success ends a streak of log..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/reflex-frontend/tests/state_connection.test.js">

<violation number="1" location="packages/reflex-frontend/tests/state_connection.test.js:330">
P3: The test only covers two consecutive 405s, so it does not prove the log re-arms after a streak ends. Add a successful exchange between failure streaks and assert that a second message is logged.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

The next failure after a successful exchange is logged again. Removing the reset of the failure count on success makes the test fail with one message instead of two.
@FarhanAliRaza FarhanAliRaza added the on deck PRs lined up to review / merge next label Nov 30, 2026
@codspeed

codspeed Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 16 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 146 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing farhan/session-exchange-error-console (27cd436) with main (7ee72a1)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant