-
-
Notifications
You must be signed in to change notification settings - Fork 62
UpdateSubscription getting disposed when the BittrexSocketClient is disposed #208
Description
Describe the bug
I'm trying to use the DI to inject the clients into app services that is provided by AddBittrex() and I'm injecting the IBittrexSocketClient as a scoped service to perform the subscription operation. Right after the request handling is completed the client gets disposed and all of the subscriptions created by the client get disposed as well. As I understand, the socket client here shouldn't maintain all subscription dependencies and it's used only to create them and subscription should be handled by the SignalR hub and a calling dependencies themselves. I could switch to the singleton socket client, but it doesn't seem right. The same behavior is observed on Binance clients and Bittrex clients, didn't check the others yet.
To Reproduce
- Register clients with the code:
services.AddBittrex((client, socket) =>
{
client.LogLevel = LogLevel.Trace;
socket.LogLevel = LogLevel.Trace;
});
- Inject the
IBittrexSocketClientand create the subscriptions with the following code:
var client = serviceProvider.GetRequiredService<IBittrexSocketClient>();
_heartbeat = await client.SpotStreams.SubscribeToHeartbeatAsync(OnHeartbeat).ToException(Descriptor);
_ticker = await client.SpotStreams.SubscribeToTickerUpdatesAsync(OnTicketUpdates).ToException(Descriptor);
- With handlers:
private void OnTicketUpdates(DataEvent<BittrexTickersUpdate> data)
{
_logger.LogInformation("[{timestamp}] Ticker: {data}.", data.Timestamp, data.Topic);
}
private void OnHeartbeat(DataEvent<DateTime> data)
{
_logger.LogInformation("Heartbeat: {data}.", data);
}
Expected behavior
There should be the way to leave the subscriptions active when disposing the client. Also it seems that subscriptions should have mechanisms to recover the connections with credentials by themselves.
Debug logging
The logs display the following:
2022/02/22 21:38:29:486 | Trace | Bittrex | Socket 2 received 221 bytes in single message
2022/02/22 21:38:29:487 | Trace | Bittrex | Socket 2 received 49 bytes in single message
2022/02/22 21:38:29:491 | Debug | Bittrex | Disposing socket client, closing all subscriptions
2022/02/22 21:38:29:494 | Debug | Bittrex | Closing all 2 subscriptions