Skip to content

add event-driven auth recovery for WebSockets behind proxies#1391

Merged
richard-to merged 1 commit into
mesop-dev:mainfrom
nirben82:fix_1389
May 10, 2026
Merged

add event-driven auth recovery for WebSockets behind proxies#1391
richard-to merged 1 commit into
mesop-dev:mainfrom
nirben82:fix_1389

Conversation

@nirben82
Copy link
Copy Markdown
Contributor

@nirben82 nirben82 commented May 5, 2026

Opt-in, event-driven solution to allow applications to handle this gracefully without forcing a destructive full-page reload that loses user state.

  1. HTTP Probe: When the connection is detected as dead during user interaction, the client performs a lightweight HTTP probe using fetch with redirect: 'manual'.
  2. Event Emission: If a redirect is detected (indicating session expiry), the framework emits a mesop:auth-required CustomEvent on the window object, passing the target URL in the details.
  3. Proactive Recovery: The framework listens for the focus event on the window. When the user returns to the tab (presumably after completing the authentication flow in another window or tab), it probes again and automatically reconnects if successful.

fixes #1389

Comment thread mesop/env/env.py Outdated
Comment thread mesop/web/src/services/channel.ts Outdated
Comment thread mesop/web/src/services/channel.ts
Comment thread mesop/web/src/services/channel.ts Outdated
Comment thread mesop/web/src/services/channel.ts Outdated
this.experimentService.authProxyEnabled
) {
console.debug('Window focused, probing connection...');
const isRedirected = await this.probeConnection();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there any race condition that's possible here? Mainly trying to think what would happen if multiple probe connections were triggered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added isProbing flag to prevent concurrent async operations in TypeScript

@richard-to
Copy link
Copy Markdown
Collaborator

I'll take another look in a couple days. Busy this week.

@richard-to richard-to merged commit efca18e into mesop-dev:main May 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dead websockets connections don't reconnect when the app is behind an auth proxy

2 participants