Skip to content

Bug: initialize() doesn’t await feature fetch when using remoteEval: true #111

@OnlyTarg

Description

@OnlyTarg

When using remoteEval: true, the GBSDKBuilderApp.initialize() method calls refresh() internally, which is supposed to fetch the latest feature values from the server.

However, due to a missing await, the actual remote evaluation request is not awaited. This causes a race condition where sdk.feature(...) returns incomplete data immediately after initialization.

initialize() looks fine:
await gb.refresh();

But in refresh():

Future<void> refresh() async {
  if (_context.remoteEval) {
    refreshForRemoteEval(); // ❗ Not awaited
  } else {
    await _featureViewModel.fetchFeatures(...);
  }
}

And in refreshForRemoteEval():

await _featureViewModel.fetchFeatures(...); // This *is* awaited, but ignored by refresh()

Impact

Behavior depends on whether the app has previously run:
First app launch:
• sdk.feature() returns null, because the remote fetch hasn’t completed yet.
Subsequent launches: the SDK returns a cached (stale) value from the previous session — not the latest value from the server.
The correct value only appears:
• after a page rebuild or
• on next app launch, when cached data is already rewritten.

This makes flags unreliable at startup and introduces unexpected UI states.

See full test app here:
https://github.com/OnlyTarg/gb_refresh_test/tree/feat-init-remote-eval-bug-example

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