dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.5k stars 10.04k forks source link

WebSockets failure when proxying v8 debugger protocol #2930

Closed kumpera closed 5 years ago

kumpera commented 6 years ago

Hello everyone,

I'm using asp.net to proxy the v8 debugger protocol. It uses WebSockets.

I'm running into this exception that makes little sense to me. What could be causing it?

System.Net.WebSockets.WebSocketException: TODO, RESX: net_WebSockets_InvalidState; (Aborted,Open, CloseReceived)
   at System.Net.WebSockets.WebSocketValidate.ThrowIfInvalidState(WebSocketState currentState, Boolean isDisposed, WebSocketState[] validStates)
   at System.Net.WebSockets.ManagedWebSocket.SendAsync(ArraySegment`1 buffer, WebSocketMessageType messageType, Boolean endOfMessage, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at WsProxy.WsProxy.<Send>d__8.MoveNext() in /Users/kumpera/src/wasm/ws-proxy/WsProxy.cs:line 101
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at WsProxy.WsProxy.<SendEventInternal>d__17.MoveNext() in /Users/kumpera/src/wasm/ws-proxy/WsProxy.cs:line 187
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at WsProxy.WsProxy.<OnEvent>d__9.MoveNext() in /Users/kumpera/src/wasm/ws-proxy/WsProxy.cs:line 107
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
kumpera commented 6 years ago

It normally happens when the browser decides to send a large amount of data to the debugger.

rynowak commented 6 years ago

/cc @anurse

analogrelay commented 6 years ago

The error message is wrong because of https://github.com/aspnet/WebSockets/issues/198 which should be fixed in 2.1-preview1.

The actual error message is: "The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, Closed Received'"

It sounds like one of the parties aborted the connection. Do you have more information about the scenario (such as a repro?)? Also, is this occuring in the socket received from AcceptWebSocketAsync or from a ClientWebSocket (the latter would be an issue for dotnet/corefx) Actually the error message makes it clear because it's on the ASP.NET WebSocket that had these broken error messages.

kumpera commented 6 years ago

Hey @anurse,

The scenario is the v8 debugger being flooded with messages when the browser finishes loading a wasm file with debug data and decided to tell the debugger that there are a few thousand source files in the web page.

It works fine without the proxy, so there's something wrong somewhere in my setup (my code or asp.net core).

I'll update to 2.1-preview1 to see if anything changes.

Meanwhile, while I reduce my thing to an usable repro, would some WireShark dumps help?

analogrelay commented 6 years ago

WireShark dumps would help a lot. The key is going to be figuring out who is terminating the connection and why. ASP.NET's WebSocket implementation adds almost nothing on top of the CoreFX ManagedWebSocket implementation (in fact, in 2.1-preview1, it is literally using the same code), so there may be an issue there.

Do you have a repro I can run locally?

analogrelay commented 5 years ago

Closing this as it's gotten very stale :).