Skip to content

[browser][webSocket] Data Loss in ClientWebSocket.ReceiveAsync after server initiated close #96359

Closed
@imxcstar

Description

@imxcstar

Description

In a C# Blazor WebAssembly (WASM) application where multiple threads aren't utilized, there's an issue with the ClientWebSocket's ReceiveAsync method. Initially, data is received successfully. However, due to extended processing time for preceding data, the server disconnects before subsequent data can be retrieved using ReceiveAsync. Strangely, at the JavaScript layer, it's evident that the subsequent data has arrived (confirmed via WebSocket data in browser network captures). How can this scenario be effectively addressed?

Reproduction Steps

  1. Establish a ClientWebSocket connection in a C# Blazor WebAssembly application.
  2. Begin receiving data using the ReceiveAsync method.
  3. Process the initially received data that might take an extended period.
  4. While processing, allow enough time for additional data to arrive from the server.
  5. Observe that due to the prolonged processing time, the server disconnects before the processing completes.
  6. Monitor the WebSocket traffic using browser network tools to confirm the arrival of subsequent data.
    demo git

Expected behavior

  • The ClientWebSocket's ReceiveAsync method should continuously receive and buffer incoming data, irrespective of the time taken for processing previously received data.
  • Even if there's a delay in handling the initial data, subsequent data should be accessible via ReceiveAsync, allowing uninterrupted data reception.

Actual behavior

  • Initial data is received successfully through ReceiveAsync.
  • However, when processing takes an extended duration, the server disconnects, and subsequent data becomes inaccessible via ReceiveAsync.
  • Browser network captures indicate the arrival of subsequent data, which isn't retrievable due to the disconnection issue.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions