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

[SDK-1181] Setting clientId again. #1842

Closed
wants to merge 4 commits into from
Closed

Conversation

maratal
Copy link
Collaborator

@maratal maratal commented Nov 27, 2023

After clientId has been reset on deactivate, it will be nil during further calls to activate until app relaunch or re-auth to Ably. Fixing it by setting clientId from options again on device activation.

…g further calls to `activate` until app relaunch or re-auth to Ably. Fixing it by setting clientId again whenever accessing the local device.
@github-actions github-actions bot temporarily deployed to staging/pull/1842/features November 27, 2023 13:38 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1842/jazzydoc November 27, 2023 13:42 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1842/features December 1, 2023 15:13 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1842/jazzydoc December 1, 2023 15:19 Inactive
@maratal maratal force-pushed the fix/1177-set-clientId-again branch from 3cd914e to e39aa05 Compare December 1, 2023 17:51
@github-actions github-actions bot temporarily deployed to staging/pull/1842/features December 1, 2023 17:51 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1842/jazzydoc December 1, 2023 17:56 Inactive
@maratal maratal force-pushed the fix/1177-set-clientId-again branch from e39aa05 to edf9942 Compare December 1, 2023 19:59
@github-actions github-actions bot temporarily deployed to staging/pull/1842/features December 1, 2023 19:59 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1842/jazzydoc December 1, 2023 20:05 Inactive
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this PR is implementing RSH8b, which describes how and when the LocalDevice’s clientId should be populated.

Assuming that we're not currently conforming to RSH8b, that presumably means that we must be currently populating LocalDevice.clientId in some non spec-conforming way. Is that right? If so, should we not remove it?

@@ -117,6 +118,12 @@ - (ARTPushActivationState *)transition:(ARTPushActivationEvent *)event {
}
else if ([event isKindOfClass:[ARTPushActivationEventCalledActivate class]]) {
[self.machine registerForAPNS];
#if TARGET_OS_IOS
ARTLocalDevice *const local = self.machine.rest.device_nosync;
if ([local clientId] == nil) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the nil check? RSH8b doesn't describe this.

@maratal maratal changed the title Setting clientId again whenever accessing the local device. [SDK-1181] Setting clientId again whenever accessing the local device. Dec 8, 2023
…ar device details) and only resets clientId, since it affects push device registration with a different clientId (after deregistration with previous clientId). This only affects clients that do not restart their apps after deregistration, since clientId is loaded into deviceId once per app launch. This commit resets clientId after deregistration."

This reverts commit bff9205.
@maratal maratal changed the title [SDK-1181] Setting clientId again whenever accessing the local device. [SDK-1181] Setting clientId again. Dec 10, 2023
@maratal maratal marked this pull request as draft December 11, 2023 00:23
@maratal
Copy link
Collaborator Author

maratal commented Dec 11, 2023

Seems like according to RSH3a2a1 different clientId should have different deviceId and deviceSecret and thus to change clientId full reset device details should be performed. WDYT @lawrence-forooghian

@lawrence-forooghian
Copy link
Collaborator

I don't know what you mean by "different clientId should have different deviceId and deviceSecret". What do you mean by this, and how do you take it from reading RSH3a2a1?

@lawrence-forooghian
Copy link
Collaborator

I thought that in order to address the issue that you described in the PR description, your PR intended to implement RSH8b properly. Have I missed something?

@maratal
Copy link
Collaborator Author

maratal commented Dec 12, 2023

I don't know what you mean by "different clientId should have different deviceId and deviceSecret". What do you mean by this, and how do you take it from reading RSH3a2a1?

RSH3a2a1: "if the LocalDevice has a non-empty clientId, and the present identified client has a different (non-null) clientId" which I guess explicitly means that if the clientId in the current client (passed through options?) differs from the one saved in the LocalDevice storage (together with id and secret), then it's an error 61002. Which means, that to avoid this error, for a new clientId a new pair of device id and secret is needed.

@lawrence-forooghian
Copy link
Collaborator

RSH3a2a1 is executed "if the local device has deviceIdentityToken". But your description for the PR is talking about the user calling activate() having previously deactivated their device, which would have caused any saved deviceIdentityToken to be cleared, so how is RSH3a2a1 relevant to this situation?

@ttypic
Copy link
Contributor

ttypic commented Dec 13, 2023

@maratal @lawrence-forooghian I am not sure that the bug is covered by spec. I guess the problem is that spec says:

  • LocalDevice is lazy-singleton, it should be initialized on first call
  • LocalDevice most likely sets clientId during initialization (and I can't find any spec items that describe when it should be changed)

Customer creates several Ably instances with different clientId during App lifecycle. When they create new Ably instance, with new clientId they get LocalDevice with old clientId and send old clientId everywhere. We tried to fix it by setting LocalDevice.clientId to nil during deregistration, but it made things worse (according to customer, I think it actually makes things a little better) because now customer gets LocalDevice with clientId = nil and get errors even if clientId hasn't been changed.

Does it make sense to you guys?

Can we check clientId handling transition from not_active to the next state?

P.S. I think that LocalDevice is singleton is a bad thing, and it's holding us back

@maratal
Copy link
Collaborator Author

maratal commented Dec 13, 2023

we're not currently conforming to RSH8b

TBH I didn't understand this statement, because what load: does here is initializing clientId while generating device's id and secret a few lines below. So I think that RSH8b is implemented. @lawrence-forooghian

What this PR was initially intended to do, is to fix the first PR that was just resetting clientId which, as @ttypic said, made things looking worse, but in fact, slightly better.

Re RSH3a2a1, there are few tests, that began to fail repeatedly, and I've made erroneous assumption about RSH3a2a1, sorry 🤦‍♂️

Now I think that the best option would be to resurrect the old PR which makes full reset device details and address users complains about it accordingly.

@maratal
Copy link
Collaborator Author

maratal commented Dec 13, 2023

Ok, now I see what you've meant here re RSH8b @lawrence-forooghian

@lawrence-forooghian
Copy link
Collaborator

  • LocalDevice most likely sets clientId during initialization (and I can't find any spec items that describe when it should be changed)

I think that my old message that Marat linked to above does the best job of explaining this.

RSH8b describes when the LocalDevice’s clientId should be set. That is, it should not be set when the singleton is lazily instantiated; it should be set at a specific point in the push activation flow. This behaviour is currently missing in ably-cocoa, and is the reason why the clientId is currently not being set again after the device is re-activated.

We tried to fix it by setting LocalDevice.clientId to nil during deregistration

Yes, this was us implementing RSH3g2a, right? But that spec point needs to be implemented alongside RSH8b.

As far as I can tell, as long as we're properly implementing RSH8b and RSH3g2a, we shouldn't have any problems. Have I missed something?

@maratal
Copy link
Collaborator Author

maratal commented Dec 13, 2023

As far as I can tell, as long as we're properly implementing RSH8b and RSH3g2a, we shouldn't have any problems. Have I missed something?

I think that those specs should be implemented in different PRs, but shouldn't be shipped separately (release should contain them both).

@lawrence-forooghian
Copy link
Collaborator

Sure, we can fix them however we want. But do you agree that all we need to do is make sure we're correctly implementing those two spec points and this whole issue should go away?

@lawrence-forooghian
Copy link
Collaborator

P.S. I think that LocalDevice is singleton is a bad thing, and it's holding us back

Yes, agreed, but I think that as long as the user is properly deactivating one clientId before starting to use a different one, then it's OK right?

@maratal
Copy link
Collaborator Author

maratal commented Dec 13, 2023

Sure, we can fix them however we want. But do you agree that all we need to do is make sure we're correctly implementing those two spec points and this whole issue should go away?

Well, at least it looks like that.

@maratal
Copy link
Collaborator Author

maratal commented Dec 21, 2023

Closed in favor of #1847

@maratal maratal closed this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants