Skip to content

Initial launch crash due to race condition around Firestore PERMISSION_DENIED #737

Open
@tellypresence

Description

@tellypresence

Have ported android app which had been using native firebase to firebase-kotlin-sdk wrapper.

On initial launch following fresh install (i.e. brand new installation or following uninstall) there's a 50/50 chance the app will crash with
FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions

Expand to view stack trace com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions. at com.google.firebase.firestore.util.Util.exceptionFromStatus(Util.java:155) at com.google.firebase.firestore.core.EventManager.onError(EventManager.java:247) at com.google.firebase.firestore.core.SyncEngine.removeAndCleanupTarget(SyncEngine.java:642) at com.google.firebase.firestore.core.SyncEngine.handleRejectedListen(SyncEngine.java:478) at com.google.firebase.firestore.core.MemoryComponentProvider$RemoteStoreCallback.handleRejectedListen(MemoryComponentProvider.java:125) at com.google.firebase.firestore.remote.RemoteStore.processTargetError(RemoteStore.java:596) at com.google.firebase.firestore.remote.RemoteStore.handleWatchChange(RemoteStore.java:479) at com.google.firebase.firestore.remote.RemoteStore.access$100(RemoteStore.java:60) at com.google.firebase.firestore.remote.RemoteStore$1.onWatchChange(RemoteStore.java:188) at com.google.firebase.firestore.remote.WatchStream.onNext(WatchStream.java:114) at com.google.firebase.firestore.remote.WatchStream.onNext(WatchStream.java:38) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.lambda$onNext$1$com-google-firebase-firestore-remote-AbstractStream$StreamObserver(AbstractStream.java:126) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) at com.google.firebase.firestore.remote.AbstractStream$CloseGuardedRunner.run(AbstractStream.java:67) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.onNext(AbstractStream.java:113) at com.google.firebase.firestore.remote.FirestoreChannel$1.onMessage(FirestoreChannel.java:162) at io.grpc.internal.DelayedClientCall$DelayedListener.onMessage(DelayedClientCall.java:473) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:667) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:654) at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:524) at java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:348) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651) at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:235) at java.lang.Thread.run(Thread.java:1119) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@cf90630, Dispatchers.IO] Caused by: io.grpc.StatusException: PERMISSION_DENIED: Missing or insufficient permissions. at io.grpc.Status.asException(Status.java:541) at com.google.firebase.firestore.util.Util.exceptionFromStatus(Util.java:153) ... 27 more

But once the android app has been launched one time (whether it crashed or not), thereafter it appears to never crash again for this reason, so this problem only affects the initial launch.

On the face of it the error stack trace seems identical to that first reported in #350, but in this case it only affects the initial launch of a freshly installed app, and then not every time, so seems to be a race condition somewhere in this wrapper project; prior to porting had never seen this error over several years of development.

(Would have liked to provide more information but try/catch blocks are useless when attempting to isolate the error)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions