Skip to content

NameError (undefined local variable or method `env' when calling ld_client.variation #160

@everly-blake

Description

@everly-blake

Is this a support request?
This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the SDK code. If you're not sure whether the problem you are having is specifically related to the SDK, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going here and clicking "submit a request", or by emailing support@launchdarkly.com.

Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above.

Describe the bug
On rails 5.1.6, I am initializing ld_client per the docs on_worker_boot in my puma config. However, whenever I run code that checks ld_client.variation my application throws the above exception, presumably something in the middleware. From my testing, this only happens if ld_client isn't properly instantiated. However, I cannot get ld_client to properly initialize during startup now. This used to only happen occasionally, but now I can't get it to start at all.

To reproduce
Rails 5.1.6 using puma

on_worker_boot do ActiveRecord::Base.establish_connection Rails.configuration.ld_client = LaunchDarkly::LDClient.new(ENV['LAUNCH_DARKLY_SDK_KEY']) end

Simple check somewhere in controller: Rails.configuration.ld_client.variation('synchronous_checkout', current_user, false)

And I get the error every time now.

Expected behavior
true or false returned for that toggle, based on environment/project specific launch darkly settings.

Logs
If applicable, add any log output related to your problem.

SDK version
The version of this SDK that you are using.

Language version, developer tools
ruby 2.5.7
rails 5.1.6
launchdarkly-server-sdk (5.8.0)

OS/platform
OSX Mojave 10.14.1

Additional context
Within a console, if I manually run the initialization code it works, so I don't know if this is something puma specific or what.

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