Skip to content

LockRecursionException During LdClient.Init() on Xamarin Android (SDK 4.0.0) #310

@neerajgroverflynn

Description

@neerajgroverflynn

Calling LdClient.Init() in a Xamarin Android project using LaunchDarkly SDK version 4.0.0 consistently throws a System.Threading.LockRecursionException, even when following all recommended practices.

🔧 Environment
Platform: Xamarin Android
SDK Version: LaunchDarkly SDK 4.0.0
Device: Pixel 6, Android 13 (also reproducible on other devices)
Threading Context: Initialization is done on a background thread with TimeSpan.Zero.
💥 Error Message
System.Threading.LockRecursionException: Recursive write lock acquisitions not allowed in this mode.
at System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore...
at LaunchDarkly.Sdk.Client.Internal.LockUtils.WithWriteLock[T]...
at LaunchDarkly.Sdk.Client.LdClient..ctor...
at LaunchDarkly.Sdk.Client.LdClient.Init...
🧪 What I’ve Tried
Using TimeSpan.Zero for non-blocking initialization.
Ensuring LdClient.Init() is called only once.
Avoiding any external locks or shared state during initialization.
Delaying initialization using Task.Delay() to avoid SDK internal conflicts.
Running initialization on a background thread.
Ensuring the Context object is immutable and not reused.

Sample Code:

C#
public static void Init(Context LDContext)
{
Task.Run(async () =>
{
await Task.Delay(1000); // Delay to avoid SDK internal conflicts

    var config = Configuration.Builder(ConstantsData.LDMobileKey,
        ConfigurationBuilder.AutoEnvAttributes.Disabled).Build();

    var timeSpan = TimeSpan.Zero;

    ldClient = LdClient.Init(config, LDContext, timeSpan);
});

}

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