#websocket connection reset, client error
15 messages · Page 1 of 1 (latest)
Hi @proud river. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, connection reset errors and WebSocket connection closures do occasionally happen with Convex, as reported by several users. These issues can sometimes be related to network conditions, browser state, or even temporary infrastructure problems.
Some users have experienced situations where the WebSocket fails to connect or gets closed, resulting in errors like "WebSocket connection closed" or "WebSocket error: undefined." In many cases, reloading the page does resolve the issue, but the root cause can vary. For example:
- Network or ISP issues: Sometimes, the problem is specific to a device or network, and switching to a VPN or another device can make Convex work again. There have been cases where security vendors or ISPs temporarily block Convex domains, causing connection failures. These blocks are sometimes lifted, resolving the issue without user intervention.
- Client state issues: Occasionally, the Convex client can get into a stale or unauthenticated state, especially after being in the background or after a network reconnection. Refreshing the browser often restores the connection and authentication state.
- Temporary Convex infrastructure issues: There have been rare cases of broader outages or backend issues, but these are typically resolved quickly by the Convex team.
If you encounter frequent WebSocket connection resets, it's a good idea to:
- Try reloading the page.
- Test on a different network or device.
- Enable verbose logging on the Convex client for more detailed error information.
- If the problem persists, check the Convex Discord or status page for any ongoing incidents, or contact support.
References:
- WebSocket connection issues and network dependencies
- Client state and authentication issues after reconnects
- ISP/security vendor blocks and VPN workarounds
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@proud river Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@shut crystal i setup convex auth correctly and its fine on web. however on mobile i keep getting logged out. session persistence is basically non-existent. find potential causes and fixes.
Let me check the knowledge base for you again. One moment! :books:
There are several known causes for session persistence issues with Convex Auth on mobile (especially with React Native/Expo), even when things work fine on web. Here are the most common causes and potential fixes, based on the knowledge sources:
1. Token Storage Issues (Expo SecureStore vs. react-native-keychain)
- Many users have reported that using Expo SecureStore for token storage can lead to unpredictable logouts, especially after the app is backgrounded for a long time or when the device state changes (e.g., charging, orientation). This is often due to iOS Keychain security constraints, which can prevent access to stored tokens in the background, causing the app to lose authentication state.
- Fix: Switch from
expo-secure-storetoreact-native-keychainfor storing tokens. Multiple users have reported that this change resolved their session persistence issues, and Sentry logs of "User interaction is not allowed" errors disappeared after the switch.
See discussion and solution
2. Convex Client Token Refresh Race Conditions
- There are known race conditions in the Convex client where, after the app is backgrounded for a long time, the client may try to use an expired token or fail to refresh it properly. This can cause the user to appear logged out until the app is fully restarted.
- Fix: The Convex team is actively working on fixes for these race conditions. In the meantime, ensuring that your app properly re-initializes authentication state on resume, and using the latest Convex client, may help.
See staff comments on ongoing fixes
3. Auth State Mismatch Between Clerk and Convex
- If you use Clerk with Convex, sometimes Clerk will show the user as authenticated, but Convex will not, especially after long background periods. This can result in being stuck on the sign-in screen until the app is killed and restarted.
- Fix: Ensure your auth navigation logic checks both Clerk and Convex auth state, and consider adding logging to diagnose mismatches. Also, see if switching token storage (as above) resolves the issue.
See detailed troubleshooting and code examples
4. Session Duration and Expiry
- By default, Convex sessions have a limited duration and may expire if inactive for too long. While session duration is not always configurable, you can check the Convex Auth server settings for
sessionTotalDurationMsand related options if you need longer sessions. - Fix: Review your Convex Auth configuration and consider opening an issue if you need longer session durations.
See session duration discussion
5. Debugging Tips
- Enable verbose logging in the Convex client to get more insight into what’s happening with auth state and token refreshes.
- Clear local storage/secure storage to rule out corrupted state.
- Add UI or console logs to display both Clerk and Convex auth state for easier debugging on device.
Debugging guide
Summary of recommended actions:
- Switch from Expo SecureStore to react-native-keychain for token storage.
- Update to the latest Convex client.
- Add logging to compare Clerk and Convex auth state.
- Enable verbose logging for deeper debugging.
- Monitor for upcoming Convex client fixes related to backgrounding and token refresh.
If you follow these steps and still experience issues, it may be worth reaching out on the Convex Discord with detailed logs and your setup.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@proud river Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@shut crystal i mean on the browser on mobile, not locally using react native/expo
Let me check the knowledge base for you again. One moment! :books:
Thank you for clarifying that your issue is with Convex Auth session persistence in the mobile browser (not React Native/Expo).
Based on the knowledge sources, here are the most relevant potential causes and fixes for session persistence issues on mobile browsers:
1. Session Cookie Expiry and Storage
- On web (including mobile browsers), Convex Auth typically uses cookies for session storage, especially with Next.js and SSR. By default, these are often "session cookies," which means they are deleted when the browser is closed. This can cause users to be logged out after closing the browser, even on mobile.
- Fix: You can configure cookie expiration to persist sessions across browser restarts. See the Convex Auth Next.js documentation for how to set a longer cookie expiration:
Configure cookie expiration
This will help keep users logged in even after closing and reopening the browser on mobile devices.
2. Browser-Specific Behavior
- Some mobile browsers may handle cookies and local storage differently, especially in private/incognito mode or with aggressive memory management. This can lead to unexpected logouts.
- Fix: Test your app in different browsers (Safari, Chrome, etc.) and ensure you are not in private mode. If issues persist only in certain browsers, it may be due to their storage policies, which are outside Convex's control.
3. Convex Client State Issues
- There are known issues where the Convex client can get into a state where it believes the user is not authenticated, even if the token is still valid. Refreshing the browser usually restores the session. This can happen due to race conditions or if queries are made before the auth state is fully propagated.
- Fix: Make sure all authenticated queries are gated behind an
<Authenticated>component or use theuseConvexAuthhook to ensure the client is ready before making requests.
See discussion on client state and race conditions
4. Convex Package Version
- There have been reports that upgrading to the latest Convex package resolved session persistence issues for some users.
- Fix: Ensure you are using the latest version of the Convex packages.
See user report on package upgrade fixing the issue
If you have already set up cookie expiration and are using the latest Convex packages but still experience issues, please provide more details about your setup and browser environment. There may be edge cases or ongoing fixes in the Convex client related to session persistence.
Summary:
- Set a persistent cookie expiration for Convex Auth.
- Ensure all queries wait for authentication state.
- Use the latest Convex packages.
- Be aware of browser-specific storage policies.