Skip to content

WebSocket sends can overlap despite the send lock #23

@nficano

Description

@nficano

src/Arcp.Client/Transport/WebSocket.fs documents that concurrent sends are serialized through sendLock, but sendOne only holds the lock while creating the socket.SendAsync task. The task is awaited after the lock has been released, so two callers can enter SendAsync concurrently on the same WebSocket. The BCL WebSocket contract allows only one send operation at a time, and overlapping sends from auto-ack, pong, submit, cancel, or close paths can throw or corrupt message ordering under load.

Fix prompt: replace the synchronous obj lock in WebSocketClientTransport.sendOne with an async-aware serializer such as SemaphoreSlim. Await WaitAsync ct, call and await socket.SendAsync while the semaphore is held, and release it in a finally block. Add a focused unit or integration test using a fake or loopback WebSocket transport that starts multiple SendAsync calls concurrently and verifies the underlying sends do not overlap and preserve envelope order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:highHigh severity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions