websocket-client icon indicating copy to clipboard operation
websocket-client copied to clipboard

How to handle receiving messages in large sizes?

Open Janecifer opened this issue 3 years ago • 2 comments

Hi Marfusios,

Thanks for this great lib. Mat I trouble you how to handle large messages? It works well in small sizes of data. But we have a situation that may receive the 10M data, then it will throw an Exception.

[ERR] [WEBSOCKET CLIENT] Error while listening to websocket stream, error: 'An exception caused the WebSocket to enter the Aborted state. Please see the InnerException, if present, for more details.' System.Net.WebSockets.WebSocketException (0x80004005): An exception caused the WebSocket to enter the Aborted state. Please see the InnerException, if present, for more details. at System.Net.WebSockets.ManagedWebSocket.CloseWithReceiveErrorAndThrowAsync(WebSocketCloseStatus closeStatus, WebSocketError error, String errorMessage, Exception innerException) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Threading.Tasks.ValueTask1.GetTaskForValueTaskSource(IValueTaskSource`1 t) --- End of stack trace from previous location --- at Websocket.Client.WebsocketClient.Listen(WebSocket client, CancellationToken token)

We try to add an option for increasing the buffer size, but it didn't help. _ clientFactory.Options.SetBuffer(20971520, 10240);

Thanks for help!

Janecifer avatar Sep 06 '22 02:09 Janecifer

Hey @Janecifer , what is the InnerException?

Marfusios avatar Dec 19 '22 08:12 Marfusios

I have the same issue, the inner exception is null. The exception I have is:

   at System.Net.WebSockets.ManagedWebSocket.CloseWithReceiveErrorAndThrowAsync(WebSocketCloseStatus closeStatus, WebSocketError error, String errorMessage, Exception innerException)
   at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask`1.GetTaskForValueTaskSource(IValueTaskSource`1 t)
--- End of stack trace from previous location ---
   at Websocket.Client.WebsocketClient.Listen(WebSocket client, CancellationToken token)

m17kea avatar Sep 07 '23 19:09 m17kea