Skip to content

[Remote Config] Initialize ConfigInfo fields and fix Android EnsureInitialized throttled_end_time - #1998

Open
AustinBenoit wants to merge 2 commits into
mainfrom
fix/remote-config-configinfo-init
Open

AustinBenoit wants to merge 2 commits into
mainfrom
fix/remote-config-configinfo-init

Conversation

@AustinBenoit

Copy link
Copy Markdown
Contributor

Description

Fixes #1997 (and the underlying root cause of firebase/firebase-unity-sdk#1481).

In remote_config/src/android/remote_config_android.cc, EnsureInitializedCallback() declared ConfigInfo info; uninitialized and passed it to JConfigInfoToConfigInfo(), which never set info->throttled_end_time (unlike RemoteConfigInternal::GetInfo()). Because struct ConfigInfo had no default member initializers, EnsureInitialized() returned stack garbage for throttled_end_time on Android—causing intermittent System.ArgumentOutOfRangeException in Unity's ConfigInfo constructor whenever stale stack bytes exceeded DateTime.MaxValue.

Summary of changes:

  • Public header (remote_config/src/include/firebase/remote_config.h): Default-initialize all fields on struct ConfigInfo (fetch_time = 0, last_fetch_status = kLastFetchStatusPending, last_fetch_failure_reason = kFetchFailureReasonInvalid, throttled_end_time = 0).
  • Android (remote_config/src/android/remote_config_android.{h,cc}):
    • Thread throttled_end_time into JConfigInfoToConfigInfo() and populate it in EnsureInitializedCallback() (both success and failure paths).
    • Guard against nullptr jinfo in GetInfo() / JConfigInfoToConfigInfo() and check JNI exceptions before converting fetch_time / status_code.
    • Capture throttle end times on FetchAndActivate() via FetchAndActivateCallback + UpdateThrottledEndTimeFromResult() (matching Fetch() and iOS).
    • Store throttled_end_time_ in std::atomic<uint64_t> and drain util::CancelCallbacks() at the start of Cleanup() before ReleaseClasses() / util::Terminate().
  • iOS (remote_config/src/ios/remote_config_ios.{h,mm}):
    • Store throttled_end_time_in_sec_ in std::atomic<int64_t> strictly before completing futures, only updating on positive NSNumber throttle timestamps (preserving throttle state on non-throttled errors and populating config_info.throttled_end_time on EnsureInitialized() error).
    • Clamp negative/non-finite fetch_time and guard against overflow when converting seconds to milliseconds.
  • Desktop (remote_config/src/desktop/rest.cc): Clamp negative MillisecondsSinceEpoch() to 0.
  • Tests & release notes: Added unit tests in metadata_test.cc and remote_config_desktop_test.cc, added TestEnsureInitialized in remote_config/integration_test/src/integration_test.cc, and updated release_build_files/readme.md.

Testing

  • C++ Desktop Debug and ASan+UBSan (ctest --output-on-failure -R remote_config): 4/4 targets, 50/50 gtest cases passed, 0 sanitizer errors, 0 warnings on modified lines.
  • Android NDK 23.2.8568313 (r23c) and 28.2.13676358 (r28b), aarch64 & armv7a (remote_config_android.cc and remote_config.cc with -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 with g++ -std=c++17 -Wall -Wextra.
  • Paired Unity SWIG (SWIG 4.4.1) + Firebase.RemoteConfig.dll build against this branch: 0 SWIGTYPE_p_ leaks, 0 compiler warnings.
  • Verified python3 scripts/format_code.py --git_diff --noformat_file and ./scripts/gha/check_copyright.sh -g.

Type of Change

Place an x in the applicable box:

…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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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.
AustinBenoit added a commit to firebase/firebase-unity-sdk that referenced this pull request Nov 27, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

throttled_end_time in ConfigInfo uninitialized

1 participant