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

Non-sendable type Query / CollectionReference cause warnings in any actor-isolated context #12666

Closed
SwiftfulThinking opened this issue Mar 29, 2024 · 5 comments · Fixed by #13453

Comments

@SwiftfulThinking
Copy link

SwiftfulThinking commented Mar 29, 2024

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 to Query and CollectionReference. Is there an approach to avoid this or can these classes become Sendable?

Notes:

  • These warnings appear after setting Strict Concurrency Checking to Complete.
  • I wasn't sure whether to label this as a bug and I couldn't find anything in the documentation explaining how to avoid this.

Reproducing the issue

Screenshot 2024-03-29 at 7 40 24 PM

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 snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@wu-hui
Copy link
Contributor

wu-hui commented Apr 2, 2024

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!

@fanwgwg
Copy link

fanwgwg commented Jun 28, 2024

@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 QuerySnapshot or DocumentSnapshot across different threads?

For instance, we listen to Firestore on a utility queue by setting firestoreSettings.dispatchQueue = DispatchQueue(label: "firestore", qos: .utility) because we often handle large collections. However, the converted data sometimes needs to be consumed by the UI on the main thread. Therefore, I'd like to know if it's safe to pass the snapshot objects between threads.

@mortenbekditlevsen
Copy link
Contributor

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.
Would that work for you?

@fanwgwg
Copy link

fanwgwg commented Jun 29, 2024

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 :)

@paulb777 paulb777 self-assigned this Aug 9, 2024
@firebase firebase locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy