Skip to content

Streaming PATCH updates are not reflected in client store #76

@bjreath

Description

@bjreath

I'm running into the following scenario while upgrading to ldclient-rb 2.0.3 from ldclient-rb 0.7.0. The gem is used within a Rails 4.2.7.1 application on Puma.

The feature flags are working fine in our development environment when the application first loads, and it appears the correct values are returned initially. However, if a user goes to the LaunchDarkly web interface and toggles a flag, the update is not reflected within the Rails application until the Rails server is killed and restarted. This led me to believe we might be having an issue with handling PATCH server-sent event passed back from LaunchDarkly when the flag is changed.

In config/initializers/launch_darkly.rb:

config = LaunchDarkly::Config.new(connect_timeout: 2, read_timeout: 2, offline: false)
Rails.configuration.features_client = LaunchDarkly::LDClient.new(ld_api_key, config)

We then use this global in our code to check for enabled features. As is the default, the LaunchDarkly::StreamProcessor is configured as the update processor within the client. I put some logging into this class to see if the PATCH SSEs are being received and handled, and it does appear that they are.

message = JSON.parse(message.data, symbolize_names: true)
@config.logger.info("[LDClient] Before #{@store.get(message[:path][1..-1])}")
@store.upsert(message[:path][1..-1], message[:data])
@config.logger.info("[LDClient] After #{@store.get(message[:path][1..-1])}")

This correctly reflects a new version number for the flag and the proper on value in the message.

However, any time the global LaunchDarkly::LDClient#variation method is accessed on Rails.configuration.features_client for the flag, the variation code returns the initial version that was present when the LDClient was initialized on this line, which causes us to hit the condition here that returns the default flag value. It seems the update to the store is not being picked up from the client (even though accessing the store directly from the StreamProcessor logging statements above seem to indicate that the store was updated properly).

I'm continuing to dig in to see if I can identify the issue, but any pointers would be appreciated.

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