Skip to content

Fixes Connection issues#4

Merged
martian56 merged 1 commit intomainfrom
fix-con-issues
Nov 7, 2025
Merged

Fixes Connection issues#4
martian56 merged 1 commit intomainfrom
fix-con-issues

Conversation

@martian56
Copy link
Owner

This pull request introduces several backend and frontend improvements focused on reliability, error handling, and developer experience. The backend now ensures safer participant host assignment and more robust error handling during WebSocket connections. The frontend improves WebSocket reconnection logic and provides fallback defaults for API configuration, making local development easier.

Backend reliability and error handling:

  • Ensured the first active participant in a meeting is safely assigned as host using a transaction-safe approach, preventing race conditions. [1] [2]
  • Improved error handling when creating participants: now logs errors, closes the WebSocket with a proper error code, and ensures the meeting exists before proceeding.
  • Enhanced the broadcast_to_meeting function to safely remove dead WebSocket connections, preventing issues from modifying the connection list during iteration.
  • Added support for HTTP HEAD requests on the /health endpoint for better health checks.

Frontend configuration and connection handling:

  • Provided default values for API_BASE_URL and WS_BASE_URL in config.ts, simplifying local development when environment variables are missing.
  • Improved WebSocket reconnection logic in useWebSocket.ts to prevent unwanted reconnections and memory leaks by checking component mount status and cleaning up references. [1] [2]
  • Updated dependencies in the WebSocket message handler in MeetingRoom.tsx to include localStream and chatOpen, ensuring correct effect execution.

@martian56 martian56 requested a review from Copilot November 7, 2025 17:53
@martian56 martian56 self-assigned this Nov 7, 2025
@martian56 martian56 added bug Something isn't working enhancement New feature or request labels Nov 7, 2025
@martian56 martian56 merged commit 8ab7f8b into main Nov 7, 2025
6 of 7 checks passed
Copy link

Copilot AI left a comment

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 addresses WebSocket connection management and stability issues by improving reconnection logic, error handling, and race condition prevention. It also adds fallback configuration values and health check endpoint support.

  • Improved WebSocket reconnection logic to prevent multiple concurrent connections
  • Fixed race condition in host assignment by checking participant count before creating records
  • Added error handling and dead connection cleanup in broadcast functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
frontend/src/hooks/useWebSocket.ts Enhanced WebSocket cleanup with mounted state tracking and proper null assignment on disconnect
frontend/src/pages/MeetingRoom.tsx Added localStream and chatOpen to dependency array for WebSocket message handler
frontend/src/config.ts Added fallback values for API and WebSocket URLs when environment variables are not set
backend/main.py Fixed race condition in host assignment, added HEAD method support for health endpoint, improved broadcast error handling, and enhanced connection cleanup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


useEffect(() => {
connect();
let isMounted = true;
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The isMounted variable is declared but never used. It's set to true on line 93 and to false on line 96 in the cleanup function, but there are no checks against this variable anywhere in the code. Either remove this unused variable or add logic to check isMounted before reconnecting in the ws.onclose handler to prevent reconnection attempts after component unmount.

Copilot uses AI. Check for mistakes.
user_agent = websocket.headers.get("user-agent", "Unknown")

# Get or create meeting in database
meeting = None
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The meeting variable is initialized to None before the database block and checked again after at line 234. However, if the meeting is not found, the code already returns at line 188, making the check at line 234 redundant. The initialization at line 177 and the check at lines 234-235 can be removed to simplify the code flow.

Copilot uses AI. Check for mistakes.
@martian56 martian56 added this to the MVP version milestone Nov 9, 2025
@martian56 martian56 moved this from Backlog to Done in LinkUp Project Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants