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

Reconnecting on the close event stops event handler AggregateTradeWebSocketClient.AggregateTrade firing #41

Closed
rakewell opened this issue Jan 30, 2018 · 3 comments

Comments

@rakewell
Copy link

Hello,

I seem to have an issue with reconnecting the socket in the Close event (DefaultWebSocketClient.Close) . If I disconnect by executing Cancel on the token service and then reconnect with another button, the service reconnects successfully. But if I try and reconnect in the close event the AggregateTradeWebSocketClient.AggregateTrade event stop firing. The socket is transmitting data, however, because I can see aggregate trade update messages in the DefaultWebSocketClient.Message event handler
TryConnectOnClose.zip

The best way I can demonstrate is with a sample application. See attached.

@sonvister sonvister self-assigned this Jan 30, 2018
@sonvister
Copy link
Owner

@rakewell unfortunately I did mention the Close event could be used in that way (although I did not recommend it).... Regardless, you can't reconnect on the Close event Thread. Assuming you are awaiting the call, that will prevent the Close event handler from returning.

@sonvister
Copy link
Owner

@rakewell, I appreciate the simplicity of you giving me the code to try in order to demonstrate the issue and I have no reason to believe you have any ill intentions. However, I still have to worry about security. So, sorry, I did not look at or run the code you provided. And yes, the fact you are running code I provide is not lost on me... if the code were visible on GitHub I could at least look at it without worry.

@rakewell
Copy link
Author

@sonvister thanks for your reply and I understand you not wanting to run the project. At this point you understand the problem so there's no need to post the code.

I managed to reconnect the socket on another thread using:
Dim cnnTask = Task.Run(Async Sub() ConnectSocket())

This allowed the socket to reconnect and continue streaming successfully.

I am also trying to get the RetryTaskController to work but am having problems. Here is the following code that I am using to run the controller:

`

Me.UnSubscibeAllTradeUpdatesManaged()
Me.m_BinanceAggregateTradeSocketCancel = New CancellationTokenSource

For Each assRow In Me.m_AssetPrices
    Me.m_BinanceAggregateTradeSocket.Subscribe(assRow.Key)
Next

m_SocketConnectionRetryTaskController = New RetryTaskController

Using m_SocketConnectionRetryTaskController
    m_SocketConnectionRetryTaskController.Begin(Function() As Task
                                                    Return m_BinanceAggregateTradeSocket.StreamAsync(m_BinanceAggregateTradeSocketCancel.Token)
                                                End Function)
End Using`

When the open event is called:
`

Private Sub m_BinanceSocketTradeStreamClient_Open(sender As Object, e As EventArgs) Handles m_BinanceTradeSocketStreamClient.Open
    Try

        If Me.InvokeRequired Then
            Me.Invoke(New Action(Of Object, EventArgs)(AddressOf Me.m_BinanceSocketTradeStreamClient_Open), sender, e)
        Else
            Me.TradeSocketStatusGroup.BackColor = Color.LightGreen
            Me.TradeSocketStatusGroup.ForeColor = Color.Black
        End If

    Catch ex As Exception
        HandleSocketApiException(ex)
    End Try

End Sub`

It seems to lock the UI thread on the line:
Me.Invoke(New Action(Of Object, EventArgs)(AddressOf Me.m_BinanceSocketTradeStreamClient_Open), sender, e)

Does the retry task controller lock the UI thread while it is in operation? Is there any way I can achieve a re-connection with the RetryTaskController without locking the UI Thread?

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

No branches or pull requests

2 participants