Skip to content
This repository was archived by the owner on Oct 18, 2018. It is now read-only.
This repository was archived by the owner on Oct 18, 2018. It is now read-only.

WebSocket.ReceiveAsync throws exceptions #92

@NVentimiglia

Description

@NVentimiglia

I am porting over my networking library to dotnetcore. My websocket transport is nearly identical, except I am using Kestrel instead of an HTTP Listener. When I call ReceiveAsync, I get request aborted exceptions. If I add an arbitrary yield, the error changes to a NRE.

        public Task<WebSocketReceiveResult> ReadAsync()
        {
            buffer = new ArraySegment<byte>(BufferFactory.Rent(BufferFactory.MAXIMUM_SIZE));

            //THROWS HERE
            return webSocket.ReceiveAsync(buffer, CancellationToken.None);
        }


        public async void Update()
        {
            try
            {
                 // await Task.Yeild; // arbitrary yield for exception 2.

                //THROWS HERE
                var received = await ReadAsync();

                while (webSocket != null && received.MessageType != WebSocketMessageType.Close)
                {
                    if (received.MessageType == WebSocketMessageType.Binary)
                    {
                        OnDataReceive(this, buffer.Array);
                        received = await ReadAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                OnException(this, ex);
            }
            finally
            {
                Close();
            }
        }

Without the yield I get this exception

The request was aborted

When I add the yield my exception changes to this

Cannot access a disposed object.\r\nObject name: 'FrameRequestStream'.

Stack Trace

" at Microsoft.AspNetCore.Server.Kestrel.Http.SocketInput.GetResult()\r\n at Microsoft.AspNetCore.Server.Kestrel.Http.SocketInputExtensions.d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.WebSockets.Protocol.CommonWebSocket.d__38.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.WebSockets.Protocol.CommonWebSocket.d__37.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.WebSockets.Protocol.CommonWebSocket.d__36.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at Signaling.Server.Ws.WSConnection.d__35.MoveNext() in G:\Drive\Avarice\Foundation\Foundation.Signaling\Signaling\Signaling.Server.Ws\WSConnection.cs:line 67"

ClientSide I am using Websocket4Net and WebsocketSharp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions