Repository navigation
[Remote Config] Initialize ConfigInfo fields and fix Android EnsureInitialized throttled_end_time - #1998
[Remote Config] Initialize ConfigInfo fields and fix Android EnsureInitialized throttled_end_time#1998AustinBenoit wants to merge 2 commits into
Conversation
…itialized throttled_end_time (#1997) Fixes #1997. - Default-initialize all fields of ConfigInfo in remote_config.h. - Thread throttled_end_time into JConfigInfoToConfigInfo and populate it in Android EnsureInitializedCallback (and guard against null jinfo and JNI exceptions). - Capture throttle end times on Android FetchAndActivate() via FetchAndActivateCallback, store throttled_end_time_ atomically, and drain JNI task callbacks in Cleanup() before ReleaseClasses()/util::Terminate(). - On iOS, store throttled_end_time_in_sec_ atomically strictly before completing futures, only update on positive NSNumber throttle timestamps, clamp negative/non-finite fetch_time, and prevent overflow when converting seconds to milliseconds. - On Desktop, clamp negative MillisecondsSinceEpoch() to 0. - Add unit tests (metadata_test.cc, remote_config_desktop_test.cc), integration test (integration_test.cc), and Upcoming release note.
There was a problem hiding this comment.
Code Review
This pull request addresses several issues in Remote Config across Android, iOS, and Desktop platforms. Key changes include adding default member initializers to ConfigInfo, capturing throttle end times from Android's FetchAndActivate, and clamping negative or out-of-range timestamps to prevent wrapping. Additionally, throttled_end_time is now managed using atomic variables to ensure thread safety. The reviewer recommends declaring callbacks_cancelled_ as std::atomic<bool> in remote_config_android.h to prevent potential data races during cleanup and destruction.
| // String to be used when registering for JNI task callbacks. | ||
| std::string jni_task_id_; | ||
|
|
||
| bool callbacks_cancelled_ = false; |
There was a problem hiding this comment.
Since callbacks_cancelled_ is accessed and modified outside of the ReferenceCountLock in Cleanup() and can potentially be accessed concurrently or across different threads during cleanup/destruction, it should be declared as std::atomic<bool> to prevent data races and undefined behavior.
| bool callbacks_cancelled_ = false; | |
| std::atomic<bool> callbacks_cancelled_{false}; |
- Revert 4 unrelated clang-format hunks in remote_config_desktop_test.cc (fixes CI file_format_check).
- Poison storage with 0xAA + placement-new default-init in ConfigInfoDefaultInitialized test for mutation resistance.
- Guard non-finite/out-of-range NSNumber doubles in iOS UpdateThrottledEndTimeFromError.
- Clarify Cleanup() comment ('Cancel' instead of 'Drain') to match util::CancelCallbacks semantics.
…st and static readonly UnixEpochUtc Let firebase/firebase-cpp-sdk#1998 fix the underlying Android uninitialized ConfigInfo::throttled_end_time bug at the root rather than clamping in C#, keeping ConfigInfo consistent with StorageMetadata, AppCheckToken, UserMetadata, and IdTokenResult.
Description
Fixes #1997 (and the underlying root cause of firebase/firebase-unity-sdk#1481).
In
remote_config/src/android/remote_config_android.cc,EnsureInitializedCallback()declaredConfigInfo info;uninitialized and passed it toJConfigInfoToConfigInfo(), which never setinfo->throttled_end_time(unlikeRemoteConfigInternal::GetInfo()). Becausestruct ConfigInfohad no default member initializers,EnsureInitialized()returned stack garbage forthrottled_end_timeon Android—causing intermittentSystem.ArgumentOutOfRangeExceptionin Unity'sConfigInfoconstructor whenever stale stack bytes exceededDateTime.MaxValue.Summary of changes:
remote_config/src/include/firebase/remote_config.h): Default-initialize all fields onstruct ConfigInfo(fetch_time = 0,last_fetch_status = kLastFetchStatusPending,last_fetch_failure_reason = kFetchFailureReasonInvalid,throttled_end_time = 0).remote_config/src/android/remote_config_android.{h,cc}):throttled_end_timeintoJConfigInfoToConfigInfo()and populate it inEnsureInitializedCallback()(both success and failure paths).nullptrjinfoinGetInfo()/JConfigInfoToConfigInfo()and check JNI exceptions before convertingfetch_time/status_code.FetchAndActivate()viaFetchAndActivateCallback+UpdateThrottledEndTimeFromResult()(matchingFetch()and iOS).throttled_end_time_instd::atomic<uint64_t>and drainutil::CancelCallbacks()at the start ofCleanup()beforeReleaseClasses()/util::Terminate().remote_config/src/ios/remote_config_ios.{h,mm}):throttled_end_time_in_sec_instd::atomic<int64_t>strictly before completing futures, only updating on positiveNSNumberthrottle timestamps (preserving throttle state on non-throttled errors and populatingconfig_info.throttled_end_timeonEnsureInitialized()error).fetch_timeand guard against overflow when converting seconds to milliseconds.remote_config/src/desktop/rest.cc): Clamp negativeMillisecondsSinceEpoch()to0.metadata_test.ccandremote_config_desktop_test.cc, addedTestEnsureInitializedinremote_config/integration_test/src/integration_test.cc, and updatedrelease_build_files/readme.md.Testing
ctest --output-on-failure -R remote_config): 4/4 targets, 50/50 gtest cases passed, 0 sanitizer errors, 0 warnings on modified lines.23.2.8568313(r23c) and28.2.13676358(r28b),aarch64&armv7a(remote_config_android.ccandremote_config.ccwith-std=c++17 -DINTERNAL_EXPERIMENTAL=1 -Wall -Wextra): compiled cleanly with 0 errors and 0 warnings on modified lines.remote_config/integration_test/src/integration_test.cc: compiled cleanly withg++ -std=c++17 -Wall -Wextra.SWIG 4.4.1) +Firebase.RemoteConfig.dllbuild against this branch: 0SWIGTYPE_p_leaks, 0 compiler warnings.python3 scripts/format_code.py --git_diff --noformat_fileand./scripts/gha/check_copyright.sh -g.Type of Change
Place an
xin the applicable box: