Skip to content

Commit ff845d5

Browse files
committed
always use the source feature store before wrapping
1 parent 8579305 commit ff845d5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/ldclient-rb/impl/data_system/fdv1.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ def initialize(sdk_key, config)
3838
@data_store_broadcaster
3939
)
4040

41-
# Wrap the data store with client wrapper (must be created before status provider)
41+
# Preserve the original unwrapped store to avoid nested wrappers on postfork
42+
original_store = @config.feature_store
43+
if original_store.is_a?(LaunchDarkly::Impl::FeatureStoreClientWrapper)
44+
original_store = original_store.instance_variable_get(:@store)
45+
end
46+
47+
# Wrap the original data store with client wrapper (must be created before status provider)
4248
@store_wrapper = LaunchDarkly::Impl::FeatureStoreClientWrapper.new(
43-
@config.feature_store,
49+
original_store,
4450
@data_store_update_sink,
4551
@config.logger
4652
)

spec/impl/data_system/fdv1_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ module DataSystem
1515
subject # Force creation of FDv1 instance
1616
expect(config.data_source_update_sink).to be_a(LaunchDarkly::Impl::DataSource::UpdateSink)
1717
end
18+
19+
it "wraps the feature store with FeatureStoreClientWrapper" do
20+
original_store = config.feature_store
21+
subject # Force creation of FDv1 instance
22+
23+
wrapped_store = config.feature_store
24+
expect(wrapped_store).to be_a(LaunchDarkly::Impl::FeatureStoreClientWrapper)
25+
expect(wrapped_store.instance_variable_get(:@store)).to eq(original_store)
26+
end
27+
28+
it "avoids nested wrappers when config.feature_store is already wrapped" do
29+
# First initialization wraps the store
30+
original_store = config.feature_store
31+
first_fdv1 = FDv1.new(sdk_key, config)
32+
first_wrapper = config.feature_store
33+
expect(first_wrapper).to be_a(LaunchDarkly::Impl::FeatureStoreClientWrapper)
34+
35+
# Second initialization (simulating postfork) should unwrap and re-wrap the original
36+
second_fdv1 = FDv1.new(sdk_key, config)
37+
second_wrapper = config.feature_store
38+
expect(second_wrapper).to be_a(LaunchDarkly::Impl::FeatureStoreClientWrapper)
39+
40+
# The inner store should be the original, not the first wrapper
41+
inner_store = second_wrapper.instance_variable_get(:@store)
42+
expect(inner_store).to eq(original_store)
43+
expect(inner_store).not_to be_a(LaunchDarkly::Impl::FeatureStoreClientWrapper)
44+
end
1845
end
1946

2047
describe "#start" do

0 commit comments

Comments
 (0)