ringcentral / RingCentral.Net

RingCentral SDK for .NET
MIT License
19 stars 26 forks source link

NullReference when revoking a subscription that wasn't Subscribed #29

Closed BryceBarbara closed 3 years ago

BryceBarbara commented 4 years ago

As the title says, you can't currently cancel a subscription when you have the SubscriptionInfo object for it although it seems like you should.

Here's some example code explaining the scenario I'm trying to do:

var subscriptionInfos = await GetActiveSubscriptionsWeDontNeed();
foreach (var subInfo in subscriptionInfos) {
  var sub = new Subscription(_rc, subInfo.eventFilters, OnSubscriptionMessage) {
    subscriptionInfo = subInfo
  };
  await sub.Revoke();
}

Although I'm not positive, it looks like this might be the problem line: https://github.com/ringcentral/RingCentral.Net/blob/7635cc8e4d34639dab4751f9ddc333f1d47a86cd/RingCentral.Net.PubnubPCL/Subscription.cs#L115

tylerlong commented 4 years ago

If you never Subscribe, you don't have to call Revoke. You just de-reference it and it will be garbage collected by .NET runtime.

You can see that the constructor doesn't consume any system/network resource: https://github.com/ringcentral/RingCentral.Net/blob/7635cc8e4d34639dab4751f9ddc333f1d47a86cd/RingCentral.Net.PubnubPCL/Subscription.cs#L45-L57. So there is nothing to revoke.

But I get your point, it's better to add some sanity check and do nothing to revoke if there is nothing to revoke.

BryceBarbara commented 4 years ago

I'm trying to cancel a subscription that was started in another instance that fatally exited. I've found that if I don't cancel it in advance, I get duplicate notifications.

There's currently no way to cancel the orphaned subscriptions with the system as it stands.

tylerlong commented 4 years ago

I'm trying to cancel a subscription that was started in another instance that fatally exited.

What do you mean by "fatally exited"? And what is "another instance"? Do you mean another app process or another subscription object?

There's currently no way to cancel the orphaned subscriptions with the system as it stands.

There is, as long as you have the subscription ID. You just invoke this https://github.com/ringcentral/RingCentral.Net/blob/7635cc8e4d34639dab4751f9ddc333f1d47a86cd/RingCentral.Net.PubnubPCL/Subscription.cs#L101

You cannot invoke pubnub.Destroy because in your case for some reason pubnub is null. (which I think is because you never subscribed, but you said it is because instance fatally exited)

tylerlong commented 3 years ago

In latest version, code has been changed to _pubnub?.Revoke() which will not throw if _pubnub is null.