barrywood78 / Coinbase.AdvancedTrade

Coinbase Advanced Trade API Wrapper
8 stars 1 forks source link

Unhandled Exception thrown at arbitrary time #11

Closed Lumaswell closed 3 months ago

Lumaswell commented 7 months ago

If you run the websocket long enough, it'll eventually throw an unhandled exception in 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll. I'm an amateur coder at best, so I don't know how to debug this. I'm pasting the debug windows and the call stack below. Code built in visual studio 2022, .net standard 8.0, windows forms app, c#

Debug output: Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll 'BackToCoinbase2023.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.1\System.Diagnostics.StackTrace.dll'. 'BackToCoinbase2023.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.1\System.Reflection.Metadata.dll'. 'BackToCoinbase2023.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.1\System.Collections.Immutable.dll'. Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll The thread 0x4374 has exited with code 0 (0x0). The thread 0x28a8 has exited with code 0 (0x0). The thread 0x1538 has exited with code 0 (0x0). The thread 0xaf40 has exited with code 0 (0x0). Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll The thread 0xec24 has exited with code 0 (0x0). The thread 0xc2fc has exited with code 0 (0x0). Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll The thread 0x3fe8 has exited with code 0 (0x0). The thread 0x6088 has exited with code 0 (0x0). Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll Extracted embedded document "Windows.Win32\PInvoke.cs" to "C:\Users\randomname\AppData\Local\Temp.vsdbgsrc\0df52d1b10bd467156d7779655eed95718a4d019b31d1c2fa76e3f51331db71e\PInvoke.cs"

Call Stack Window:

System.Windows.Forms.Primitives.dll!Windows.Win32.PInvoke.WaitMessage() Line 26600 C# System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.Microsoft.Office.IMsoComponentManager.FPushMessageLoop(nuint dwComponentID, Microsoft.Office.msoloop uReason, void* pvLoopData) Line 233 C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Microsoft.Office.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1280 C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Microsoft.Office.msoloop reason, System.Windows.Forms.ApplicationContext context) Line 1199 C# BackToCoinbase2023.dll!BackToCoinbase2023.Program.Main() Line 14 C#

Lumaswell commented 7 months ago

Update: So after much work, the websocket is getting put into a state of "Aborted". I'm currently attempting to figure out how to reset this as closing the websocket does not function in this state.

barrywood78 commented 3 months ago

@Lumaswell Good day, I know your issues was from Feb so I apologize for not getting back to you as I've been quite busy. I have just updated the project with many modifications. Specific to your issue, I have implemented the following:

  1. I have increased the buffer size of the WebSocket to 5MB as it was originally very low (128KB)
  2. I have also added an optional WebSocket buffer size to the CoinbaseClient constructor if you'd like set a custom buffer size for your needs
  3. Added a property within the WebSocketManager called WebSocketState that will return the state of the websocket. You can use this to trigger off a reconnection if required.
  4. I have added another WebSocket Test application called WebSocketReconnectionTestApp to the solution which demonstrates the use of this new property as well as a Subscriptions property to show which channels are currently subscribed to. In addition, the test application triggers a disconnect and reconnect every 30 seconds to demo how to reconnect based on the WebSocketState.

Hope this helps resolve this issue. Thanks! Barry