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

Issue when changing multiple keys in macOS Monterey #53

Closed
paxos opened this issue Oct 22, 2021 · 7 comments
Closed

Issue when changing multiple keys in macOS Monterey #53

paxos opened this issue Oct 22, 2021 · 7 comments

Comments

@paxos
Copy link

paxos commented Oct 22, 2021

First off: Thank you for this library. This is exactly what I was looking for.

There seems to be a sync issue with macOS Monterey (tested version: 12.0.1 (21A558))

It seems that Apple changed the behavior on how it posts the NSUbiquitousKeyValueStore.didChangeExternallyNotification notification.

Formerly, notification.userInfo?[NSUbiquitousKeyValueStoreChangedKeysKey] contained ALL changed keys (including ZephyrSyncKey). In my tests, this is no longer the case. Instead, the notification gets posted multiple times, with different values. Here is what happens in my scenario:

We have Client A and Client B. Lets say A changes 2 keys. What happens is:

Zephyr:

  • Receives NSUbiquitousKeyValueStore.didChangeExternallyNotification notification for key 1, stores remote value to local user defaults.
  • Zeyphr sets local sync date
  • Receives NSUbiquitousKeyValueStore.didChangeExternallyNotification notification for key 2, throws it away, because local sync date is newer
  • Receives NSUbiquitousKeyValueStore.didChangeExternallyNotification notification for key ZephyrSyncKey

Zephyr/Sources/Zephyr.swift

Lines 456 to 459 in d86fe8c

if let localStoredDate = zephyrLocalStoreDictionary[ZephyrSyncKey] as? Date,
!(remoteStoredDate.timeIntervalSince1970 > localStoredDate.timeIntervalSince1970) {
return
}

In this scenario, the second value was thrown out and both apps are no longer in sync.

I can't tell if this is a (beta) bug or if this is the new, expected behavior. I can't think of a good way to fix this, as we would now need to store the sync date of each property - or somehow batch all those updates coming in.

@ArtSabintsev
Copy link
Owner

Thanks for the callout.

If this is in a beta build, I'd wait it out. I don't know how to fix it either. If this turns out to be a massive problem then I'll spend some time thinking on it.

Let me know what you see in newer betas.

@paxos
Copy link
Author

paxos commented Oct 22, 2021

Forgot to mention: I also filled a radar. I can put it on Open Radar as well.

@ArtSabintsev
Copy link
Owner

That sounds like a great idea!

@ArtSabintsev
Copy link
Owner

Closing for now - please reopen if you still see this issue.

@paxos
Copy link
Author

paxos commented Dec 6, 2021

Issue is still existent on Monterey 12.0.1 as well as 12.1 Beta 1.

I would recommend reopening this. The library does not work in this form on Monterey unfortunately :-/

@paxos
Copy link
Author

paxos commented Dec 6, 2021

I confirmed that keysDidChangeOnCloud gets called with ALL changed keys on < Monterey, but multiple times with only 1 key on Monterey.

@ArtSabintsev
Copy link
Owner

Mind opening a new ticket? I'm ooto for a few more days. Will take it from there.

Most likely will stop support macOS since I don't have time to really address this issue.

Arthur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants