Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access violation issue while using LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL for HTTP and HTTPS proxy workaround #438

Open
Mayank-Rk-Gupta opened this issue Sep 26, 2024 · 5 comments
Labels
bug Something isn't working c bindings Related to the C bindings for an SDK. documentation Improvements or additions to documentation package: sdk/client Issues affecting the C++ Client SDK waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness.

Comments

@Mayank-Rk-Gupta
Copy link

Mayank-Rk-Gupta commented Sep 26, 2024

Is this a support request?
No

Describe the bug
I'm experiencing an access violation error while using the LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL for proxy configuration. This issue arises because LaunchDarkly v3 currently lacks direct support for proxy settings. Despite following the correct implementation steps, the error persists. I’ve attached a screenshot for reference to provide more context on the issue. Please investigate this matter furthe

To reproduce
See the attached screenshot
Expected behavior
Should not give me the access violation.

SDK version
3.6.3

Language version, developer tools
C++17 on Visual Studio 2022 ( Version 17.8.14).

OS/platform
Windows 10.

Additional context

Example code

const auto proxy = getProxy();
    if (!proxy.empty())	
        LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL(ConfigBuilder, proxy.c_str());
@Mayank-Rk-Gupta Mayank-Rk-Gupta added bug Something isn't working package: sdk/client Issues affecting the C++ Client SDK labels Sep 26, 2024
@cwaldren-ld
Copy link
Contributor

cwaldren-ld commented Sep 28, 2024

Hi @Mayank-Rk-Gupta , what I'm seeing in your screenshot is an Access Violation on line 78:

mContext = LDContextBuilder_Build(mContextBuilder);

This is likely not related to the RelayProxyBaseURL call.

Can you please show the code where you allocate your mContextBuilder? I suspect that it's a null pointer.

The proper way to create a Context would be (example):

LDContextBuilder context_builder = LDContextBuilder_New();
LDContextBuilder_AddKind(context_builder, "user", "example-user-key");
LDContextBuilder_Attributes_SetName(context_builder, "user", "Mayank");
LDContext context = LDContextBuilder_Build(context_builder);

@cwaldren-ld cwaldren-ld added the waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness. label Sep 28, 2024
@Mayank-Rk-Gupta
Copy link
Author

Mayank-Rk-Gupta commented Sep 28, 2024

Hi @cwaldren-ld, I started the implementation of my code without proxy and I am not getting any error in Context = LDContextBuilder_Build(ContextBuilder);, and I am able to use and test end to end functionality of my code using LD v3. However after including these lines of code

const auto proxy = getProxy();
    if (!proxy.empty())	
        LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL(ConfigBuilder, proxy.c_str());

I am getting the access violation in Context = LDContextBuilder_Build(ContextBuilder); line. I have again checked the code by commenting out the proxy workaround and it is working as per expected.

@cwaldren-ld
Copy link
Contributor

I think I see the issue from your screenshot. It looks like you are calling RelayProxyBaseURL on the mConfigBuilder after it has already been built.

You can only call the builder methods on the mConfigBuilder before it is built.

In other words, this is correct:

LDClientConfigBuilder mConfigBuilder = LDClientConfigBuilder_New("sdk-123");
LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL(mConfigBuilder, proxy.c_str());

LDClientConfig config;
LDStatus status = LDClientConfigBuilder_Build(mConfigBuilder, &config);

// Now you can pass the config to LDClientSDK_New.
// NOTE: You cannot access mConfigBuilder now, it was freed. 

This is not correct:

LDClientConfigBuilder mConfigBuilder = LDClientConfigBuilder_New("sdk-123");


LDClientConfig config;
LDStatus status = LDClientConfigBuilder_Build(mConfigBuilder, &config);

// WARNING: This is undefined behavior! 
// The mConfigBuilder object was already freed by C++ destructor on the previous line.
 LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL(mConfigBuilder, proxy.c_str());

// Accessing it may cause a crash, or worse.
// You cannot call a configuration method after you have already built the config.

@cwaldren-ld cwaldren-ld added waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness. documentation Improvements or additions to documentation c bindings Related to the C bindings for an SDK. and removed waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness. labels Sep 30, 2024
@Mayank-Rk-Gupta
Copy link
Author

Hi @cwaldren-ld, I tried

LDClientConfigBuilder ConfigBuilder = LDClientConfigBuilder_New("sdk-123");
LDClientConfigBuilder_ServiceEndpoints_RelayProxyBaseURL(ConfigBuilder, proxy.c_str();
LDClientConfig config;
LDStatus status = LDClientConfigBuilder_Build(mConfigBuilder, &config);

LDClientSDK client = LDClientSDK_New(config, context);

However when I LDClientSDK_Start to initiate the client sdk, using below code

bool initialized_successfully = false;
    if (LDClientSDK_Start(client, INIT_TIMEOUT_MILLISECONDS,
                          &initialized_successfully)) {
        if (initialized_successfully) {
            printf("*** SDK successfully initialized!\n\n");
        } else {
            printf("*** SDK failed to initialize\n");
            return 1;
        }
    } else {
        printf("SDK initialization didn't complete in %dms\n",
               INIT_TIMEOUT_MILLISECONDS);
        return 1;
    }

it is getting failed to initialize the sdk and I test again without adding proxy, It is succesfully able to initiliaze the sdk.

@cwaldren-ld
Copy link
Contributor

Hi @Mayank-Rk-Gupta , glad to hear the access violation is resolved.

I suspect it is something to do with the proxy.

  1. Can you run your executable with LD_LOG_LEVEL=debug ./executable and paste the logs?
  2. Does the proxy require authentication?
  3. Can you paste the proxy.c_str() value?

Please, redact any sensitive information if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c bindings Related to the C bindings for an SDK. documentation Improvements or additions to documentation package: sdk/client Issues affecting the C++ Client SDK waiting for feedback Indicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness.
Projects
None yet
Development

No branches or pull requests

2 participants