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

[BUG] OnPubSubServiceConnected is called when disconnecting from PubSub #121

Open
ArcadeArchie opened this issue Sep 1, 2023 · 2 comments

Comments

@ArcadeArchie
Copy link

i have a asp.net core hosted service that looks like this, when i stop the service at runtime(i.e. stream went down so pubsub is no longer needed) the disconnect works as expected but for some reason OnPubSubServiceConnected is triggered which it shouldnt

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
    _logger.LogInformation("Starting pubsub connection");
    try
    {
        _logger.LogInformation("Getting userId for {userName}", _options.TargetChannel);
        var res = await _apiClient.Helix.Users.GetUsersAsync(logins: new List<string> { _options.TargetChannel });

        if (!res.Users.Any())
            return;
        var user = res.Users[0];
        _pubSubClient.OnChannelPointsRewardRedeemed += _pubSubClient_OnChannelPointsRewardRedeemed;
        _pubSubClient.OnLog += _pubSubClient_OnLog;
        _pubSubClient.OnListenResponse += _pubSubClient_OnListenResponse;
        _pubSubClient.OnPubSubServiceConnected += async (o, e) => _pubSubClient.SendTopics(await RequestToken());
        _pubSubClient.ListenToChannelPoints(user.Id);
        _pubSubClient.ListenToUserModerationNotifications(user.Id, user.Id);

        _pubSubClient.Connect();

        _logger.LogInformation("Connected to pubsub");
        while (!stoppingToken.IsCancellationRequested) ;
    }
    catch (TaskCanceledException) { }
    catch (Exception e)
    {
        _logger.LogCritical(e, "PubSub worker failed unexpectly.");
    }
    finally
    {
        _logger.LogInformation("Stopping pubsub");
        _pubSubClient.Disconnect();
    }
}

image

@ArcadeArchie
Copy link
Author

im using

  • Twitchlib.Api 3.9.0
  • Twitchlib.EventSub.Webhooks 2.3.0
  • Twitchlib.PubSub 3.2.6

@Bukk94
Copy link

Bukk94 commented Jan 3, 2024

@ArcadeArchie Kinda late reply, but current (stable) version of TwitchLib.PubSub is using TwitchLib.Communication version 1.0.4 as an underlying client. This version of the communication library had issues with reconnection and proper disconnects. So instead of truly disconnecting, it just automatically reconnected, causing new OnPubSubServiceConnected to be fired again (you should also see active connection for that service).

This is already (mostly) fixed by new 2.0 communication version (there is still one more pending bug) and PubSub should be updated to 4.0 version.
If you don't want to wait for stable, you can try using preview versions of the packages.

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