firebase / firebase/firebase-cpp-sdk

[Bug] High CPU utilisation after authentication when running in sandbox on desktop (macOS)

Aperta
#1,045 19 commenti 8 reazioni 0 assegnatari Vedi su GitHub
api: auth type: bug
Lingua principale
C++
Stelle
326
Fork
137
Merge medio
3g 9h
PR unite (30g)
5

Descrizione

### [REQUIRED] Please fill in the following fields:

* Pre-built SDK from the [website](https://firebase.google.com/download/cpp) or open-source from this repo: Pre-built
* Firebase C++ SDK version: 9.3
* Problematic Firebase Component: Auth (Auth, Database, etc.)
* Other Firebase Components in use: Firestore (Auth, Database, etc.)
* Platform you are using the C++ SDK on: Mac ARM64 & x86 (Mac, Windows, or Linux)
* Platform you are targeting: Desktop (iOS, Android, and/or desktop)

### [REQUIRED] Please describe the issue here:

When running the Firebase C++ SDK in a sandboxed app on macOS 12.5, high CPU utilisation is observed after authentication succeeds. Without sandboxing enabled, the issue does not occur.

#### Steps to reproduce:

Follow these steps to set up a test project that reproduces the issue. Or use the attached test project below.

1. Include Firebase Auth in a C++ or Objective-C++ class and implement an email + password authentication step.
2. Create an Xcode project with the template macOS → Application → App (Interface XIB, in order to select language Objective-C). Add your C++/Objective-C++ class to this project and the app target.
3. Under project → targets → $appname, add firebase_auth.framework (from fb_cpp_sdk/frameworks/darwin/universal/ in the pre-built C++ SDK folder) to the section "Frameworks, Libraries and Embedded Content", with the option Embed & Sign selected. Also add the other macOS dependencies here (CoreFoundation, Foundation, GSS, Kerberos, libpthread, Security and SystemConfiguration. Keep the standard value for embedding, Do not Embed).
5. Check that the frameworks in fb_cpp_sdk/frameworks/darwin/universal/ either contain all headers (four header files are missing from the v9.3 download in fb_cpp_sdk/frameworks/darwin/universal/firebase.framework/Headers/) or manually add the project header search path for fb_cpp_sdk/include/.
6. The project template contains the file $appname.entitlements. Make sure that the value for key "Sandboxing enabled" in this property list file is set to YES, in order to create a sandboxed app. Additionally, set both the com.apple.security.network.client and server values to YES, in order to allow network access.
7. Build the app and run it, then sign in using email + password.
8. As soon as the authentication succeeds, four Firebase worker threads keep running at full CPU utilisation. This can be checked in the debug navigator of Xcode when selecting CPU (displays about 400% usage continuously).

Expected outcome: The worker threads should use minimal CPU resources and sleep whenever possible.

8. (Optionally) Go back to the entitlements file and set "Sandboxing enabled" to NO, in order to deactivate sandboxing. The issue should no longer occur after clean build products and rebuild in Xcode, when running the app again and signing in.

Have you been able to reproduce this issue with just the [Firebase C++ quickstarts](https://github.com/firebase/quickstart-cpp) ?
What's the issue repro rate? (eg 100%, 1/5 etc)

Yes, happens with any sandboxed Mac app build (100%).

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

As soon as the authentication succeeds, four Firebase worker keep running at full CPU utilisation.
This is mostly due to `firebase::scheduler::Scheduler::WorkerThreadRoutine`. This can be verified using Instruments, when sampling the running app.

Expected outcome: The worker threads should use minimal CPU resources and sleep whenever possible.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da firebase::scheduler::Scheduler::WorkerThreadRoutine e riproduci il problema in un’app macOS Xcode sandboxed usando l’autenticazione tramite email/password. Confronta i campioni CPU di Instruments con il sandbox abilitato e disabilitato; il lavoro è completato quando i quattro thread worker di Firebase tornano a un uso minimo della CPU dopo l’autenticazione nella build sandboxed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, macos
Ambito
authentication, desktop
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.