Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

UpdateSubscription getting disposed when the BittrexSocketClient is disposed #208

@daerhiel

Description

@daerhiel

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 IBittrexSocketClient and 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions