-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Non-sendable type Query / CollectionReference cause warnings in any actor-isolated context #12666
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
The firestore API was designed before swift actors existed. We do intend to improve the situation, but this needs to be carefully examined as the SDK is written in C++. I will add this to our todo list, but we also won't have capacity to address in the near future. Thanks for the report though! |
@wu-hui I understand that fully supporting Swift concurrency might be a significant task. However, I have a question about thread safety: is it safe to access For instance, we listen to Firestore on a utility queue by setting |
One suggestion is to do the parsing while still on the background thread, then just passing a parsed (Sendable, plain value type) model back to the main thread. |
Yes, that works, but it does create some difficulties. One of the main challenges is the need to frequently check metadata in DocumentSnapshot, such as isFromCache and hasPendingWrites. While it's certainly feasible to create a wrapper type and perform the parsing on a background thread, I find it challenging to locate clear documentation on the thread safety guarantees provided by the Firestore library. So it would be great if there is an official documentation/guidance on the thread safety of these classes :) |
Description
Any time I try to use Firestore in an actor-isolated context (ie. within an Actor or a class on the MainActor), there are warnings that
Non-sendable type... cannot cross actor boundary
. This applies toQuery
andCollectionReference
. Is there an approach to avoid this or can these classes becomeSendable
?Notes:
Reproducing the issue
Firebase SDK Version
10.23.0
Xcode Version
15.3
Installation Method
Swift Package Manager
Firebase Product(s)
Firestore
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
Expand
Package.resolved
snippetReplace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand
Podfile.lock
snippetReplace this line with the contents of your Podfile.lock!
The text was updated successfully, but these errors were encountered: