Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not handled ObjectDisposedException after disposing BinanceSocketClient #1082

Open
NektoDron opened this issue May 19, 2022 · 4 comments
Open

Comments

@NektoDron
Copy link

Describe the bug
Not handled exception after disposing BinanceClient after upgrade to 8.0.13 from 8.0.11

To Reproduce
Dispose client in reconnecting state

Expected behavior
not handled exception will be handled
FATAL:UnhandledException: System.ObjectDisposedException: The CancellationTokenSource has been disposed.
at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseInternalAsync()
at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseAsync()
at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync()
at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync(SocketSubscription subscription)
at CryptoExchange.Net.BaseSocketClient.<>c_DisplayClass37_01.<<SubscribeAsync>b_0>d.MoveNext() — End of stack trace from previous location — at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__127_1(Object state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseInternalAsync() at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseAsync() at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync() at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync(SocketSubscription subscription) at CryptoExchange.Net.BaseSocketClient.<>c_DisplayClass37_01.<b_0>d.MoveNext()
— End of stack trace from previous location —
at System.Threading.Tasks.Task.<>c.b__127_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

@JKorf
Copy link
Owner

JKorf commented May 22, 2022

Should be fixed in the latest version

@NektoDron
Copy link
Author

The same exception on 8.1.0 and CryptoExchange.Net 5.1.10.
I see CloseInternalAsync call "_ctsSource.Cancel()" and doesn't check what it was Disposed.
I can't enable the Debug mode logs because every data from Binance will be in the log and it will be to mach.

I suspect that socketConnection.CloseAsync is called from several places at the same time in my case (CheckTimeoutAsync also? ), but I don’t see any lock.

@NektoDron
Copy link
Author

I'm tried to call socketApi.UnsubscribeAllAsync() before call socketApi.Dispose but exception was the same. Library used disposed CancellationTokenSource .

@NektoDron
Copy link
Author

The problem isn't disposing socket API.
8.0.11 version is working fine without unhandled exceptions

---> call UnsubscribeAllAsync
21:41:40.65[5163]DEBUG:[BinSpotV1] API: 2022/05/27 21:41:40:660 | Information | Binance | Socket 38 Cancellation token set, closing subscription
21:41:40.65[5163]DEBUG:[BinSpotV1] Try to close all open subscription...
21:41:40.65[5163]DEBUG:[BinSpotV1] API: 2022/05/27 21:41:40:660 | Information | Binance | Closing all 1 subscriptions
21:41:40.65[8815]DEBUG:[BinSpotV1] API: 2022/05/27 21:41:40:661 | Information | Binance | Socket 38 closed

--> unhandled exception from uncontrolled pool thread
21:41:40.65[8648]FATAL:UnhandledException: System.ObjectDisposedException: The CancellationTokenSource has been disposed.
at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseInternalAsync()
at CryptoExchange.Net.Sockets.CryptoExchangeWebSocketClient.CloseAsync()
at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync()
at CryptoExchange.Net.Sockets.SocketConnection.CloseAsync(SocketSubscription subscription)
at CryptoExchange.Net.BaseSocketClient.<>c__DisplayClass41_0`1.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.<>c.b__127_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

----> dispose API
21:41:41.66[9198]DEBUG:[BinSpotV1] Disposing socket API...
21:41:41.66[9198]DEBUG:[BinSpotV1] API: 2022/05/27 21:41:41:662 | Information | Binance | Closing all 0 subscriptions

---> but application is crashed because unhandled exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants