Repository navigation
fix(html5): keep loading screen during graphql retries and show error screen on connection timeout - #24953
Conversation
… screen on connection timeout
WalkthroughThe changes introduce connection timeout handling and improved loading state management in the connection manager. A Sequence Diagram(s)sequenceDiagram
participant CM as ConnectionManager
participant GQL as GraphQL Client
participant Sub as Subscription Handler
participant Timer as Timeout Check
CM->>Sub: Subscribe (records connect start time)
Sub->>CM: Update connecting state
loop Periodic Interval (5s)
Timer->>CM: Check elapsed time
alt Elapsed > terminateAndRetry AND never connected
Timer->>CM: Set terminal error (connection_timeout)
CM->>GQL: Trigger error handler
GQL->>CM: Keep loading visible (no prior success)
else Elapsed <= terminateAndRetry
Timer->>CM: Continue monitoring
end
end
alt Connection Succeeds
GQL->>Sub: Connected event
Sub->>CM: Mark hasEverConnectedRef = true
Sub->>CM: Clear connecting timestamp
CM->>CM: Turn off loading indicator
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Pull request overview
This PR improves the HTML5 client’s startup behavior during GraphQL/WebSocket connection failures by keeping the loading UI visible while reconnect attempts happen and transitioning to an error screen if an initial connection cannot be established within a timeout.
Changes:
- Keep the loading screen visible during initial GraphQL retry failures instead of briefly hiding it.
- Add an “initial connection timeout” path that triggers a terminal error when the app never successfully connects within
terminateAndRetryConnection. - Add Playwright coverage for “loading stays visible” and “error screen appears after timeout”, plus a stable
data-testselector on the loading screen.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| bigbluebutton-tests/playwright/connectionFailure/graphqlFailure.spec.ts | Adds E2E tests for loading/error screen behavior under GraphQL connection failure. |
| bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx | Tracks initial connection attempts and adjusts loading/terminal error behavior during GraphQL failures. |
| bigbluebutton-html5/imports/ui/components/common/loading-screen/component.jsx | Adds data-test="loadingScreen" selector for reliable E2E targeting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| connectionStatus.setConnectedStatus(true); | ||
| }, | ||
| connecting: () => { | ||
| tsCurrentConnectingRef.current = Date.now(); |
There was a problem hiding this comment.
tsCurrentConnectingRef.current is overwritten on every connecting event. With graphql-ws retries, this likely resets the stopwatch each attempt, so elapsed > terminateAndRetry may never become true and the error screen will never be shown. Consider only setting the timestamp when it’s still 0 (track the start of the initial connection attempt window), and keep it unchanged across retries until a successful connected (where you already reset it).
| tsCurrentConnectingRef.current = Date.now(); | |
| if (tsCurrentConnectingRef.current === 0) { | |
| tsCurrentConnectingRef.current = Date.now(); | |
| } |
| if (elapsed > terminateAndRetry) { | ||
| setTerminalError(new Error('Unable to connect to server', { cause: 'connection_timeout' })); |
There was a problem hiding this comment.
After elapsed > terminateAndRetry, the interval will call setTerminalError(...) every 5s until the component unmounts, potentially causing repeated state updates and repeated error throws/log spam. Add a guard to only set the terminal error once (e.g., clear the interval / reset tsCurrentConnectingRef / track a hasTimedOut ref) when the timeout condition is first met.
| if (elapsed > terminateAndRetry) { | |
| setTerminalError(new Error('Unable to connect to server', { cause: 'connection_timeout' })); | |
| if (elapsed > terminateAndRetry) { | |
| clearInterval(interval); | |
| tsCurrentConnectingRef.current = 0; | |
| setTerminalError(new Error('Unable to connect to server', { cause: 'connection_timeout' })); | |
| return; |
| // Block the GraphQL WebSocket so it never connects | ||
| await page.routeWebSocket('**/graphql', () => { /* never connect */ }); |
There was a problem hiding this comment.
The routeWebSocket handler is a no-op, which may leave the initial WebSocket handshake stuck in a pending state rather than triggering failures/retries. That can make this test pass without actually exercising the retry logic (and can prevent the timeout path if the client never transitions between attempts). Prefer explicitly aborting/closing the WebSocket route (or fulfilling with a close) to force the client into its retry loop.
| // Block the GraphQL WebSocket so it never connects | |
| await page.routeWebSocket('**/graphql', () => { /* never connect */ }); | |
| // Explicitly close the GraphQL WebSocket so the client observes a real | |
| // connection failure and enters its retry/timeout logic. | |
| await page.routeWebSocket('**/graphql', async (ws) => { | |
| await ws.close(); | |
| }); |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx`:
- Around line 136-140: The connecting event handler resets
tsCurrentConnectingRef.current on every retry which prevents the timeout check
in the block that calls setTerminalError from ever elapsing; change the logic in
the code that sets tsCurrentConnectingRef.current (the handler for the
connecting event) so it only initializes the timestamp once (e.g., only set
tsCurrentConnectingRef.current if it is 0 or if hasEverConnectedRef.current is
false) and continue to reset that ref only on a successful connection or when
you explicitly give up, keeping the timeout check (using terminateAndRetry,
hasEverConnectedRef, and setTerminalError) unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 090ffd0f-e79d-4e4e-8792-13688a3b2e63
📒 Files selected for processing (3)
bigbluebutton-html5/imports/ui/components/common/loading-screen/component.jsxbigbluebutton-html5/imports/ui/components/connection-manager/component.tsxbigbluebutton-tests/playwright/connectionFailure/graphqlFailure.spec.ts
| // If the initial connection never succeeds within terminateAndRetry ms, give up and show error | ||
| if (!hasEverConnectedRef.current && tsCurrentConnectingRef.current !== 0) { | ||
| const elapsed = tsNow - tsCurrentConnectingRef.current; | ||
| if (elapsed > terminateAndRetry) { | ||
| setTerminalError(new Error('Unable to connect to server', { cause: 'connection_timeout' })); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
graphql-ws createClient on.connecting event emitted on each retry attempt lifecycle documentation
💡 Result:
Yes, in the graphql-ws library, the on.connecting event listener (type EventConnectingListener) receives a boolean parameter isRetry that indicates whether the connection attempt is a retry. This parameter is true for each retry attempt after the initial connection fails, and false for the initial connection and successful reconnections after acknowledgment. The client emits the connecting event every time it starts a new WebSocket connection, including: - The initial connection (isRetry = false) - Each retry attempt after a non-fatal close/error (isRetry = true) - After retry wait (controlled by retryWait), up to retryAttempts times This is part of the connection lifecycle: on failure (non-fatal), the client calls shouldRetry, waits via retryWait(retries), then emits connecting with isRetry=true, creates new WebSocket, etc. If it succeeds (opens + ConnectionAck), emits connected with wasRetry=true. Source code confirms: export type EventConnectingListener = (isRetry: boolean) => void; and emitted as emitter.emit('connecting'); before new WebSocket in retry flow. Official docs list it under Client events, with TypeDoc showing the isRetry param.
Citations:
- 1: https://the-guild.dev/graphql/ws/docs/client
- 2: https://the-guild.dev/graphql/ws/docs/client/interfaces/ClientOptions
- 3: https://the-guild.dev/graphql/ws/docs/client/interfaces/Client
- 4: https://github.com/enisdenjo/graphql-ws/blob/master/src/client.ts
- 5: https://github.com/enisdenjo/graphql-ws/blob/6a31f46cce25644d30253da351978e452ae583a7/src/client.ts
- 6: https://the-guild.dev/graphql/ws/docs/client/type-aliases/EventConnectingListener
🏁 Script executed:
# Check the graphql-ws version in package.json
fd -t f "package.json" | head -5 | xargs grep -l "graphql-ws" || echo "Searching in root package.json..."
rg "graphql-ws" --type json -A 1 -B 1 | head -20Repository: bigbluebutton/bigbluebutton
Length of output: 1358
🏁 Script executed:
# Examine the actual component code to confirm the issue
cat -n bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx | sed -n '300,330p'Repository: bigbluebutton/bigbluebutton
Length of output: 1696
🏁 Script executed:
# Check the entire connecting callback and surrounding context
cat -n bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx | sed -n '310,325p'Repository: bigbluebutton/bigbluebutton
Length of output: 803
Preserve the first connection-attempt timestamp across retries.
Line 321 resets tsCurrentConnectingRef.current every time the connecting event fires. In graphql-ws ^5.16.0, this event is emitted on each retry attempt, which causes the elapsed time calculation (line 139) to continuously restart. The timeout window shifts forward with each retry, preventing the connection timeout error from ever triggering.
Initialize the timestamp only once before the first successful connection:
Proposed fix
connected: (socket) => {
hasEverConnectedRef.current = true;
tsCurrentConnectingRef.current = 0;
activeSocket.current = socket as WebSocket;
connectionStatus.setConnectedStatus(true);
},
connecting: () => {
- tsCurrentConnectingRef.current = Date.now();
+ if (!hasEverConnectedRef.current && tsCurrentConnectingRef.current === 0) {
+ tsCurrentConnectingRef.current = Date.now();
+ }
connectionStatus.setConnectedStatus(false);
},🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx`
around lines 136 - 140, The connecting event handler resets
tsCurrentConnectingRef.current on every retry which prevents the timeout check
in the block that calls setTerminalError from ever elapsing; change the logic in
the code that sets tsCurrentConnectingRef.current (the handler for the
connecting event) so it only initializes the timestamp once (e.g., only set
tsCurrentConnectingRef.current if it is 0 or if hasEverConnectedRef.current is
false) and continue to reset that ref only on a successful connection or when
you explicitly give up, keeping the timeout check (using terminateAndRetry,
hasEverConnectedRef, and setTerminalError) unchanged.
✅ Automated tests have passed! |
ramonlsouza
left a comment
There was a problem hiding this comment.
tested locally by stopping the middleware service, worked well!
84430dc
into
bigbluebutton:v3.0.x-develop



What does this PR do?
When the BigBlueButton client loses connection to the server during startup, it used to briefly flash a blank screen before retrying, which was confusing. Now it keeps the loading screen visible while it retries in the background, so users always know something is happening. If the connection can't be established after a timeout, the user is taken to a proper error screen instead of being left hanging.
Closes Issue(s)
N/A
Motivation
How to test
-when join with a user blocks its graphql connection