launchdarkly / cpp-sdks

C++ Client/Server SDKs
Other
5 stars 2 forks source link

Identify and change of new context takes 4-5 minutes in version 3.x.x. #383

Closed ngangomsamananda closed 4 months ago

ngangomsamananda commented 4 months ago

We are updating client sdk (c binding) from 2.5.2 to v3.4.0 in our application. I followed the instructions given in https://docs.launchdarkly.com/sdk/features/identify to identify and change the new context.

Describe the bug In version 3.4.0, identify and change the new context takes 4-5 minutes while in v2.5.2 takes only few seconds.

To reproduce

include < iostream >

include <launchdarkly/client_side/bindings/c/sdk.h>

include <launchdarkly/bindings/c/context_builder.h>

include <launchdarkly/client_side/bindings/c/config/builder.h>

include <launchdarkly/bindings/c/object_builder.h>

include <launchdarkly/bindings/c/memory_routines.h>

include < mutex >

include

int main() { const char userid = "user-id"; const char mobile_key = "mobile-key-123-abc"; LDClientConfigBuilder ConfigBuilder = LDClientConfigBuilder_New(mobile_key); LDClientConfigBuilder_Events_PrivateAttribute(ConfigBuilder, "hubId");

LDClientConfig config;
LDStatus status = LDClientConfigBuilder_Build(ConfigBuilder, &config);
if (!LDStatus_Ok(status)) {
  std::cout<<"ldcsdk client config builder failed";
}

//LDClientConfigBuilder_Events_PrivateAttribute(ConfigBuilder, "hubId");

LDContextBuilder context_builder = LDContextBuilder_New();
LDContextBuilder_AddKind(context_builder, "user", userid);

LDContextBuilder_Attributes_SetPrivate(context_builder, "user", "email", LDValue_NewString("abc@gmail.com"));

LDContext context = LDContextBuilder_Build(context_builder);
LDClientSDK g_pLDClient = LDClientSDK_New(config, context);
unsigned int maxwait = 10 * 1000; /* 10 seconds */

bool initialized_successfully;
if (LDClientSDK_Start(g_pLDClient, maxwait, &initialized_successfully)) 
{
    if (initialized_successfully) 
    {
        std::cout << "LaunchDarkly: client Initialization Succeeded." << std::endl;
    }
    else 
    {
        std::cout<<"LaunchDarkly: client Initialization failed\n";
    }
} 
else {
        std::cout<<"LaunchDarkly: The client is still initializing.\n";
}

bool initialized = LDClientSDK_Initialized(g_pLDClient);
const char* flagName = "flag-name";
bool defaultFlagValue = false;
bool flagValue = false;
if (initialized)
{
    flagValue = LDClientSDK_BoolVariation(g_pLDClient, flagName, defaultFlagValue);
}

// Delay few seconds to replicate the timeline of application to execute the "LDClientSDK_Identify" .
// In our app this below lines of codes are executed few seconds after the clientsdk is started
std::condition_variable cv;
std::mutex mtx;
std::unique_lock<std::mutex> lck(mtx);
cv.wait_for(lck, std::chrono::milliseconds(5000));

LDContextBuilder newContextBuilder = LDContextBuilder_New();
LDContextBuilder_AddKind(newContextBuilder, "user", userid);
LDContextBuilder_Attributes_SetPrivate(newContextBuilder, "user", "email", LDValue_NewString("abc123@gmail.com"));

bool identified =false;
LDContext updatedContext = LDContextBuilder_Build(newContextBuilder);
// LDClientSDK_Identify(g_pLDClient, updated_context, LD_NONBLOCKING, NULL);

if (LDClientSDK_Identify(g_pLDClient, updatedContext, 5000, &identified))
{
    if (identified)
    {
        std::cout<<"LaunchDarkly: client identification Succeded.\n";
    }
    else
    {
        /* The specified timeout was reached, but the client is still identifying. */
    }
}
else
{
    std::cout<<"LaunchDarkly: The client is still identifying.\n";
}

bool newInitialized = LDClientSDK_Initialized(g_pLDClient);
if (newInitialized)
{
   flagValue = LDClientSDK_BoolVariation(g_pLDClient, flagName, defaultFlagValue);
}
else
{
    int count = -1;
    while (!LDClientSDK_Initialized(g_pLDClient))
    {
        std::cout << "Waiting to update the new context....\n";
        count++;
        Sleep(60000);
    }
    newInitialized = LDClientSDK_Initialized(g_pLDClient);
    if (newInitialized)
    {
        std::cout << "New context update successful.\n";
        std::cout << "Time taken to update the new context: " << 60000 * count <<" milliseconds";
        flagValue = LDClientSDK_BoolVariation(g_pLDClient, flagName, defaultFlagValue);
    }

}

}`

In the above sample code, replace userid, mobile_key and flagName with an appropriate value and run.

Expected behavior Identify and change of new context should take only few seconds just the old version (say 2.5.2). 4-5 minutes to identify and change a new context is not normal.

SDK version 3.4.0 I had also tried 3.1.0, I gives the same result.

Language version, developer tools For instance, C++17 or C11. If you are using a language that requires a separate compiler, such as C, please include the name and version of the compiler too.

OS/platform Windows 10

Additional context

cwaldren-ld commented 4 months ago

Hi @ngangomsamananda , thank you for the report. I will investigate.

Filed internally as 238745.

cwaldren-ld commented 4 months ago

I can reproduce and will work on a fix as soon as possible.

ngangomsamananda commented 4 months ago

@cwaldren-ld Thanks.

cwaldren-ld commented 4 months ago

Hi @ngangomsamananda, I have released a fix for this: v3.4.2

Please test and let me know if the issue is resolved.

ngangomsamananda commented 4 months ago

@cwaldren-ld I have tested v3.4.2 and the issue is resolved. Thanks for the quick fix.

cwaldren-ld commented 4 months ago

@ngangomsamananda thank you for your patience.