Skip to content

Fix websocket panic issue#3455

Merged
timmo001 merged 3 commits into
masterfrom
cursor/investigate-github-issue-3431-4da9
Jun 28, 2025
Merged

Fix websocket panic issue#3455
timmo001 merged 3 commits into
masterfrom
cursor/investigate-github-issue-3431-4da9

Conversation

@timmo001

@timmo001 timmo001 commented Jun 25, 2025

Copy link
Copy Markdown
Owner

Fixes #3431

A WebSocket panic due to concurrent writes was addressed by implementing per-connection write synchronization.

Key changes include:

  • A new connectionInfo struct was introduced in backend/websocket/websocket.go, embedding a *websocket.Conn and a sync.Mutex for write protection.
  • The WebsocketServer.connections map was updated to store map[string]*connectionInfo instead of map[string]*websocket.Conn.
  • The SendMessage function in backend/websocket/messages.go was refactored to accept a *connectionInfo and acquire its writeMux before calling conn.WriteJSON(), ensuring thread safety for writes to that specific connection.
  • All call sites of SendMessage and connection management functions, including AddConnection, RemoveConnection, handleMessages, BroadcastModuleUpdate, and SendError in backend/websocket/handlers.go and backend/websocket/messages.go, were updated to utilize the new connectionInfo structure.

This approach prevents concurrent writes to the same WebSocket connection, resolving the panic, while allowing concurrent writes to different connections for optimal performance.

@vercel

vercel Bot commented Jun 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
system-bridge ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2025 9:24am

@timmo001 timmo001 changed the title Investigate GitHub issue %233431 Fix websocket panic issue Jun 25, 2025
@timmo001

Copy link
Copy Markdown
Owner Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@timmo001

Copy link
Copy Markdown
Owner Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@timmo001 timmo001 force-pushed the cursor/investigate-github-issue-3431-4da9 branch from a97ab3e to f78a80c Compare June 28, 2025 09:23
@timmo001

Copy link
Copy Markdown
Owner Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@timmo001 timmo001 marked this pull request as ready for review June 28, 2025 09:32
@timmo001 timmo001 merged commit 62f141c into master Jun 28, 2025
9 checks passed
@timmo001 timmo001 deleted the cursor/investigate-github-issue-3431-4da9 branch June 28, 2025 09:39
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.

Panic on WebSocket broadcast

2 participants