Closed ngangomsamananda closed 3 months ago
Hi @ngangomsamananda , I see in your code you have:
LDListenerConnection_Disconnect(connection);
LDListenerConnection_Free(connection);
This will remove the flag listener, so you will not get any callbacks.
The first line, LDListenerConnection_Disconnect
, disconnects the listener. The second line frees the memory of the listener.
I would recommend you:
1) Delete LDListenerConnection_Disconnect
call
2) Move LDListenerConnection_Free
to the end of the script.
Let me know if this resolves the problem. Please note, if the flag value is the same for both contexts you will not get an update.
Hi @cwaldren-ld, I had tried what you had recommended but the issue is still not resolve. We use LDClientSDK_FlagNotifier_OnFlagChange
for the replacement ofLDClientRegisterFeatureFlagListener
since then we do not get the callbacks. Could you please verify if you get the callbacks of LDClientSDK_FlagNotifier_OnFlagChange
? Thanks.
Yes, I changed the code as I recommended, and I did receive the flag callback.
@ngangomsamananda Would you be able to continue this conversation with LaunchDarkly support? We could gain access to your environment and targeting rules to try and continue debugging.
@cwaldren-ld sure, let me continue this conversation with support team. Thanks!
@cwaldren-ld I have a query. We have a list of feature flags. Do I need to callLDListenerConnection_Free
for each of the listener I set in LDClientSDK_FlagNotifier_OnFlagChange ? Something like below code.
for ( i=0; i<totalFlags; i++)
{
LDFlagListener listener;
LDFlagListener_Init(&listener);
listener.FlagChanged = FlagListenerFunction;
LDListenerConnection connection = LDClientSDK_FlagNotifier_OnFlagChange(g_pLDClient, totalFlags[i], listener);
LDListenerConnection_Free(connection);
}
@cwaldren-ld I am able to get the callbacks now. Thank you.
Do I need to call
LDListenerConnection_Free
for each of the listener I set inLDClientSDK_FlagNotifier_OnFlagChange
?
Yes, if you wish to avoid memory leak at runtime, you must call LDListenerConnection_Free
for each listener.
This is because the connection is allocated on the heap and the pointer is returned to you, so you are responsible for deallocating it.
I am able to get the callbacks now. Thank you.
That is good to hear. Would you mind explaining what was the problem, so I can assist other people if they have this problem?
@cwaldren-ld Removed theLDListenerConnection_Disconnect(connection);
from the code and also the flag value was same between the two contexts.
Thank you so much for your helps.
We use
LDClientSDK_FlagNotifier_OnFlagChange
for the replacement ofLDClientRegisterFeatureFlagListener
while upgrading v2.5.2 to v3.4.2 by following the documentation https://docs.launchdarkly.com/sdk/features/flag-changes .Describe the bug The Fuction callback which is set in "LDClientSDK_FlagNotifier_OnFlagChange" does not get trigger. So, v2.5.2 the Function callback which is set using
LDClientRegisterFeatureFlagListener
got trigger when the user context is updated but not in replacement provided for v3.4.2 (i.e.LDClientSDK_FlagNotifier_OnFlagChange
)To reproduce
Expected behavior Function callback of
LDClientSDK_FlagNotifier_OnFlagChange
should get call just likeLDClientRegisterFeatureFlagListener
from v2.5.2.Logs If applicable, add any log output related to your problem. To get more logs from the SDK, change the log level using environment variable
LD_LOG_LEVEL
. For example:SDK version 3.4.2
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 Add any other context about the problem here.