Repository navigation
[DO NOT MERGE] ci(linux): probe ASan/UBSan, TSan, -Wthread-safety, and multi-App stress tests - #1976
AustinBenoit wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Clang Thread Safety Analysis (-Wthread-safety) to the Firebase C++ SDK, annotating several core classes like Mutex, CleanupNotifier, and ReferenceCountedFutureImpl to enforce compile-time thread safety checks. It also adds a new Python-based sanitizer test runner and comprehensive multi-App lifecycle stress tests (both offline and emulator-backed) to reproduce and prevent concurrency regressions. The review feedback highlights two key issues: first, an incorrect FIREBASE_REQUIRES(mutex_) annotation on RunCallback in ReferenceCountedFutureImpl that will cause a compilation failure because the lock is released before executing callbacks; second, a lack of error and timeout handling when invoking subprocess.run to list test cases in the sanitizer script, which could lead to unhandled exceptions if a binary hangs or crashes.
| void RunCallback(FutureBase* future_base, | ||
| FutureBase::CompletionCallback callback, void* user_data); | ||
| FutureBase::CompletionCallback callback, void* user_data) | ||
| FIREBASE_REQUIRES(mutex_); |
There was a problem hiding this comment.
The RunCallback function is annotated with FIREBASE_REQUIRES(mutex_). However, it is called from ReleaseMutexAndRunCallbacks which explicitly releases the mutex before running the callbacks (as noted in its documentation: 'The mutex is released before calling the callbacks'). Annotating RunCallback with FIREBASE_REQUIRES(mutex_) will cause Clang's -Wthread-safety analysis to fail with a compiler error because the mutex is not held when the callbacks are executed. Since user-defined callbacks should be executed without holding internal locks to prevent deadlocks, the FIREBASE_REQUIRES(mutex_) annotation should be removed from RunCallback.
void RunCallback(FutureBase* future_base,\n FutureBase::CompletionCallback callback, void* user_data);| proc = subprocess.run( | ||
| cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, | ||
| check=False, timeout=30 | ||
| ) |
There was a problem hiding this comment.
The subprocess.run call is executed with a timeout=30 argument but is not wrapped in a try...except subprocess.TimeoutExpired block. If the test binary hangs or deadlocks during the --gtest_list_tests phase (e.g., due to static initialization issues or sanitizer startup deadlocks), the script will crash with an unhandled exception. Additionally, if the binary crashes during listing, proc.returncode will be non-zero, which should be checked to avoid parsing incomplete or invalid output. Wrapping the execution in a try...except block and checking the return code will make the test runner more robust and ensure that a failure in one binary does not prevent other binaries from being tested.
try:\n proc = subprocess.run(\n cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,\n check=False, timeout=30\n )\n except subprocess.TimeoutExpired:\n print(f'ERROR: timeout listing tests for {binary}', flush=True)\n return []\n except Exception as exc:\n print(f'ERROR: failed to list tests for {binary}: {exc}', flush=True)\n return []\n\n if proc.returncode != 0:\n print(f'ERROR: failed to list tests for {binary} (exit code {proc.returncode})', flush=True)\n return []… and Node 22/Java 21
…US, suppress uninstrumented libglib in TSan
| /// User-supplied ID token listeners. All of these are updated when Auth's | ||
| /// ID token changes. | ||
| std::vector<IdTokenListener*> id_token_listeners; | ||
| std::vector<IdTokenListener*> id_token_listeners |
There was a problem hiding this comment.
Add #include <vector> for vector<>
Description
Diagnostic one-off draft PR to run Linux Clang
-Wthread-safety, ASan+UBSan, TSan, and multi-Applifecycle stress tests (both offline and against the Firebase emulators) on CI and collect a full baseline report.Includes:
-Wthread-safetyannotations onfirebase::Mutex/MutexLock,AuthData,CleanupNotifier,ReferenceCountedFutureImpl, andFirebaseCppCredentialsProvider(app/src/include/firebase/internal/mutex.h,auth/src/data.h,app/src/cleanup_notifier.h,app/src/reference_counted_future_impl.h,firestore/src/main/credentials_provider_desktop.{h,cc}) plus opt-incmake/thread_safety.cmake.Applifecycle unit stress test (testing/stress/multi_app_lifecycle_unit_test.cc): targets [Bug] Storage on desktop: ListenerInternal never initializes rest_operation_ #1966, [Bug] desktop UserSecureManager destructor races its scheduler when a second App has an Auth #1969, [Bug] App Check on desktop registers its token functions on the first App only, so a second App's requests carry no token #1970 (+BUG-2085FunctionRegistry::UnregisterFunction), and repeated 2-Appmulti-product create/destroy loops.Applifecycle stress test (testing/stress/multi_app_emulator_stress_test.cc): targets [Bug] desktop UserSecureManager destructor races its scheduler when a second App has an Auth #1969, [Bug] Database on desktop reconnects with no delay, retrying thousands of times a second #1971, [Bug] Auth SignOut deadlocks with Firestore asking for a token on desktop #1972, [Bug] Deleting Firestore with a write in flight frees the cleanup notifier before the write's Promise #1973, [Bug] Firestore aborts on "Cannot get token when there is no signed-in user" when a sign-out races a token request #1974 againstfirebase emulators:exec --only auth,firestore,database,storage..github/workflows/desktop.yml:linux-clang-thread-safetylinux-asan-ubsanlinux-tsanwith isolated per-test execution and a GDB deadlock watchdog (
scripts/gha/run_sanitizer_suite.py) so every test reports even if an earlier test crashes or deadlocks.Type of Change