t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Web client stays on "Still connecting" when the connection IndexedDB open never settles

Open MatiasGadeberg opened this issue 4 weeks ago • 1 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/web

Summary

In one Chrome profile the web client stayed on the FirstRunGate recovery screen ("Still connecting — T3 Code could not confirm this workspace.") on every reload. Incognito against the same server worked. The browser authenticated but never requested /.well-known/t3/environment or opened /ws. The server was fine.

I believe the cause is that indexedDB.open("t3code:connection-runtime", 4) never settled in that profile, and nothing in the web client bounds that open. This is inferred from the request trace and the code path below. I did not capture the open request itself hanging before the profile was reset.

Related: #5116 had similar symptoms, but its root cause was a corrupted HTTP disk cache that stalled module loading. That doesn't fit here: the app booted, made its auth request, and a manual fetch to the descriptor endpoint from the stalled tab returned 200. #5121 proposed a blocked handler and was closed unmerged.

Steps to reproduce

I don't have a deterministic repro. This is the sequence that led to it:

  1. Run an installed server (127.0.0.1:3773, server in WSL2) and use the web client in a normal Chrome window on Windows.
  2. Clear site data for the origin from DevTools while app tabs are open. This is my guess for what wedged the database. See the suspected cause.
  3. Reload and re-pair. The gate shows "Still connecting" after about 4 s, on every reload.

Possible unit-level repro: stub indexedDB.open to return a request that never fires any event. EnvironmentRegistry construction never completes.

Expected behavior

If browser storage can't be opened, the client still connects to the server, with a degraded offline cache, or shows an error that names browser storage as the problem.

Actual behavior

  • Pairing (POST /api/auth/browser-session) succeeds. After that, each reload makes only GET /api/auth/session. No /.well-known/t3/environment request and no /ws upgrade reach the server. t3 auth session list shows the browser session as "last connected: never".
  • In the stalled tab's console, fetch('/.well-known/t3/environment') returns 200 and window.desktopBridge is undefined. The network path works and desktop-bridge gating is not involved.
  • Server side is healthy: 12 projects / 489 threads load fine in incognito and in an isolated headless browser.
  • Clearing site data from DevTools and re-pairing does not help. Disabling all extensions does not help.
  • The recovery screen points at the workspace/server, so I spent time on server and auth before looking at the browser.

Suspected cause

All references are at cefb544af3c9.

  1. apps/web/src/connection/storage.ts:114-151: openDatabase resumes only on error (L141) and success (L144). It has no blocked listener and no timeout. Compare apps/web/src/assets/projectFaviconCache.ts:26, which rejects on blocked.
  2. packages/client-runtime/src/connection/registry.ts:223-224: EnvironmentRegistry.make reads the catalog (storage.list). This is the first read that opens the database.
  3. packages/client-runtime/src/connection/layer.ts:86-95: connection startup subscribes to platformSource.registrations only after the registry is built. That stream is what calls loadPrimaryConnectionRegistration, which fetches /.well-known/t3/environment (platform.ts:666, platform.ts:784-785).
  4. apps/web/src/components/onboarding/FirstRunGate.tsx:31, L178, L195-200: after 4 s the gate shows the generic connection message.

So a hung open stops the client right after auth. That matches the trace exactly: /api/auth/session comes from the root route's auth bootstrap, which doesn't touch IndexedDB, and nothing after it is ever requested.

Why the open would hang is unconfirmed. Two candidates:

  • A deleteDatabase issued by "Clear site data" stays pending while a document still holds a connection. Later opens queue behind it and get no event at all, not even blocked.
  • A wedged IndexedDB backend in the profile. Only a full browser restart plus deleting the site's data from Chrome settings cleared it.

A blocked handler alone probably wouldn't have helped. DATABASE_VERSION is already 4, so this was a same-version open, and the connection already closes itself on versionchange (storage.ts:174-177).

Suggested fix

  1. Bound the open: add a blocked listener and a timeout of a few seconds. Both fail with the existing ConnectionTransientError.
  2. Don't let storage gate connecting. If the open fails or times out, fall back to an in-memory backend for this page load and log a warning. The shell, thread, and server-config stores are offline caches, so losing them only costs a cold load. The catalog also stores saved remote connections. The fallback should leave the stored copy untouched rather than overwrite it with an empty catalog. Today a fast error would also fail registry construction at registry.ts:223, so the fallback covers that path too.
  3. Make the recovery screen accurate. When storage is the reason, say something like "Browser storage is unavailable. Close other T3 Code tabs or restart the browser", and log the cause so it is visible in the console.

Impact

Blocks work completely (for the affected browser profile)

Version or commit

Installed server, build cefb544af3c9

Environment

Windows, Chrome (normal profile; incognito unaffected). Server in WSL2 on 127.0.0.1:3773.

Workaround

Fully quit Chrome. Delete the site data for 127.0.0.1 via chrome://settings/content/all. Reopen and re-pair. Clearing site data from DevTools with the tab open did not work.

If you hit this, check before resetting the profile: run indexedDB.open("t3code:connection-runtime", 4) in the stalled tab's console and watch whether success, error, or blocked ever fires. That would confirm or rule out this cause.

MatiasGadeberg avatar Nov 03 '26 10:11 MatiasGadeberg

This happened again on 2026-11-23 on a newer build (8851fb79febe, server 0.1.11, same setup: Chrome on Windows, server in WSL2 on 127.0.0.1:3773). Nobody cleared site data this time. The nightly auto-deploy restarted the server, and afterwards my projects were gone from the sidebar in my normal Chrome profile.

Server trace after the restart:

  • 09:52:26: re-pair, POST /api/auth/browser-session → 200.
  • 09:52:26–09:52:39: the browser polls GET /api/auth/session and nothing else. No /.well-known/t3/environment, no /api/auth/websocket-ticket, no /ws.
  • The only /ws connection in that window came from a separate non-browser client on the same machine.

Server data was intact. The same workaround fixed it: quit Chrome fully, delete the site data for the origin in chrome://settings/content/all, re-pair.

openDatabase on current main still listens only for success and error and has no timeout, so this is consistent with the same hang. #30103 addresses it but has been idle since Nov 11, after the automated pipeline stopped. A routine server restart was enough to trigger it, so it isn't limited to people clearing site data. Could someone pick #30103 up?

MatiasGadeberg avatar Nov 23 '26 13:11 MatiasGadeberg