Skip to content

fix(html5): keep loading screen during graphql retries and show error screen on connection timeout - #24953

Merged
antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:fix/graphql/disconnection
Apr 22, 2026
Merged

antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:fix/graphql/disconnection

Conversation

@Tainan404

Copy link
Copy Markdown
Member

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

@Tainan404
Tainan404 requested a review from Copilot April 22, 2026 02:39
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce connection timeout handling and improved loading state management in the connection manager. A data-test attribute is added to the LoadingScreen component for test targeting. The ConnectionManager component now tracks connection lifecycle with refs, implements a periodic timeout check, and conditionally manages the loading indicator based on whether a successful connection has ever been established. A new Playwright test validates the loading screen remains visible during connection retries and that the error UI appears after the timeout threshold is exceeded.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main changes: keeping the loading screen visible during GraphQL retries and showing an error screen on timeout.
Description check ✅ Passed The description is directly related to the changeset, explaining the user-facing problem being solved and the implementation approach with clear context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI 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.

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-test selector 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();

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Suggested change
tsCurrentConnectingRef.current = Date.now();
if (tsCurrentConnectingRef.current === 0) {
tsCurrentConnectingRef.current = Date.now();
}

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +140
if (elapsed > terminateAndRetry) {
setTerminalError(new Error('Unable to connect to server', { cause: 'connection_timeout' }));

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +13
// Block the GraphQL WebSocket so it never connects
await page.routeWebSocket('**/graphql', () => { /* never connect */ });

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
// 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();
});

Copilot uses AI. Check for mistakes.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 88ed5e5 and 8c4b6fb.

📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/components/common/loading-screen/component.jsx
  • bigbluebutton-html5/imports/ui/components/connection-manager/component.tsx
  • bigbluebutton-tests/playwright/connectionFailure/graphqlFailure.spec.ts

Comment on lines +136 to +140
// 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' }));

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.

⚠️ Potential issue | 🟠 Major

🧩 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:


🏁 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 -20

Repository: 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.

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@ramonlsouza ramonlsouza added this to the Release 3.0 milestone Apr 22, 2026

@ramonlsouza ramonlsouza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tested locally by stopping the middleware service, worked well!

@antobinary
antobinary merged commit 84430dc into bigbluebutton:v3.0.x-develop Apr 22, 2026
62 of 65 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.

4 participants