Skip to content

Hub broadcast case releases RLock before iterating clients slice exposing it to concurrent modification #7049

@aashu2006

Description

@aashu2006

User Request

Type: bug
Target: Console Application
Submitted by: @aashu2006
Console Request ID: d163dd4e-8e1d-4150-b205-fc4602cfdd54

Description

What happened:
In pkg/api/handlers/websocket.go:155-166, the broadcast case acquires h.mu.RLock(), takes a local alias to h.userIndex[msg.userID] (sharing the underlying array), then releases RUnlock() before iterating the slice. DisconnectUser acquires RLock and reads the same userIndex while Hub.Run's unregister case holds Lock() and modifies the slice via append, potentially mutating the array that the broadcast iteration is reading.

What I expected:
The RLock should be held for the full iteration, or the slice contents (not just the header) should be copied before releasing the lock.

Steps to reproduce:

  1. Run with -race flag
  2. Trigger concurrent broadcast and user disconnection
  3. Observe race detector flag on the shared slice array

This issue was automatically created from the KubeStellar Console.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-fix-requestedai-processingAI is currently processing this issuekind/bugCategorizes issue or PR as related to a bug.triage/acceptedIndicates an issue or PR is ready to be actively worked on.triage/neededNeeds triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions