Skip to content

Conversation

@patricioxavier8
Copy link
Contributor

Removed the unnecessary ThreadSafeReference and resolveSyncedNode usage. Since findSyncedNode returns an unmanaged object, it is already thread-safe and can be used directly across threads without causing concurrency violations.

@patricioxavier8 patricioxavier8 self-assigned this Jan 25, 2026
Copy link
Member

@sg-gs sg-gs left a comment

Choose a reason for hiding this comment

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

The description states that findSyncedNode returns an unmanaged object, but this isn't accurate. Looking at the implementation:

func findSyncedNode(url: URL, deviceId: Int) -> SyncedNode? {
    let realm = try getRealm()
    return realm.objects(SyncedNode.self)
        .filter("url == %@ AND deviceId == %@", url.absoluteString, deviceId)
        .first
}

This returns a managed object directly from realm.objects(). Per Realm's threading documentation:

"Instances of Realm, Results, List, or managed Objects are thread-confined. You can only use them on the thread where you created them."

To get an actual unmanaged (thread-safe) object, you'd need to create a detached copy:

return SyncedNode(value: managedNode)

Could you clarify why removing ThreadSafeReference is safe here? Is it because all calls happen on the same thread?

@patricioxavier8
Copy link
Contributor Author

The description states that findSyncedNode returns an unmanaged object, but this isn't accurate. Looking at the implementation:

func findSyncedNode(url: URL, deviceId: Int) -> SyncedNode? {
    let realm = try getRealm()
    return realm.objects(SyncedNode.self)
        .filter("url == %@ AND deviceId == %@", url.absoluteString, deviceId)
        .first
}

This returns a managed object directly from realm.objects(). Per Realm's threading documentation:

"Instances of Realm, Results, List, or managed Objects are thread-confined. You can only use them on the thread where you created them."

To get an actual unmanaged (thread-safe) object, you'd need to create a detached copy:

return SyncedNode(value: managedNode)

Could you clarify why removing ThreadSafeReference is safe here? Is it because all calls happen on the same thread?

If it's due to the previous change implemented for handling concurrency and threads, I found that it's causing an error in that function precisely because of that handling.

@patricioxavier8 patricioxavier8 requested a review from sg-gs January 27, 2026 14:07
@patricioxavier8 patricioxavier8 merged commit 80e5a5a into release/2.6.3 Jan 27, 2026
1 check passed
@patricioxavier8 patricioxavier8 deleted the fix/removed-unnecesary-thread-reference branch January 27, 2026 15:32
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

Successfully merging this pull request may close these issues.

2 participants