Skip to content

[FR]: Provide data race prevention for custom App Check providers #11579

Open
@sruncimanraileasy

Description

@sruncimanraileasy

Description

For my current app, we have implemented a custom provider for App Check, as the SDK allows. This allows us to work around some bugs in the default implementation (e.g. #10561). Although not explicitly made clear in the guide, the phrase "The App Check SDK handles token caching, so always get a new token in your implementation of getToken(completion:)." meant that in my custom implementation, I enforced no synchronisation around token generation, expecting that the Firebase SDK would only request one token at a time. In production however, we have observed that the Firebase SDK can and will request an App Check token, whilst previous token generation flows are already in progress, leading to data races in our client.

The documentation does not explicitly provide any guarantees around data races here, and of course, by implementing custom provider, the SDK has no way of knowing about how tokens are being generated. However I would suggest that calls to getToken() on an instance conforming to AppCheckProvider are synchronised in some way, so that only one token generation can occur at a time.

I guess there is a philosophical question about whether this prevention should occur within the SDK, or whether this should be entirely the responsibility of the implementing client, which is why I am raising this as a feature request and not a bug. Thankfully, it is trivial to implement locking in the client when using Swift (Thanks Swift Actors!) 😄

In summary:
Asynchronous implementations of getToken() on custom AppCheckProvider instances currently must perform their own locking logic, to guard against multiple tokens being generated concurrently for a given app. I propose the SDK handles this, so that only one getToken() invocation can occur at any one time.

API Proposal

No response

Firebase Product(s)

App Check

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions