diff --git a/.changeset/quiet-cycles-shutdown.md b/.changeset/quiet-cycles-shutdown.md new file mode 100644 index 0000000..11c3120 --- /dev/null +++ b/.changeset/quiet-cycles-shutdown.md @@ -0,0 +1,6 @@ +--- +"posthog-ruby": patch +"posthog-rails": patch +--- + +Clear the feature flag call dedupe cache on shutdown. diff --git a/lib/posthog/client.rb b/lib/posthog/client.rb index 5f80feb..014badc 100644 --- a/lib/posthog/client.rb +++ b/lib/posthog/client.rb @@ -790,6 +790,9 @@ def shutdown @worker&.shutdown @worker_thread&.join(1) end + @distinct_id_has_sent_flag_calls_mutex.synchronize do + @distinct_id_has_sent_flag_calls.clear + end end private diff --git a/spec/posthog/client_spec.rb b/spec/posthog/client_spec.rb index 3a4a609..553f236 100644 --- a/spec/posthog/client_spec.rb +++ b/spec/posthog/client_spec.rb @@ -1534,6 +1534,14 @@ def run end describe '#shutdown' do + it 'clears feature flag call dedupe cache' do + client.instance_variable_get(:@distinct_id_has_sent_flag_calls)['user'] = ['flag_true'] + + client.shutdown + + expect(client.instance_variable_get(:@distinct_id_has_sent_flag_calls).length).to eq(0) + end + it 'is idempotent and stops accepting new events' do worker = instance_spy(PostHog::NoopWorker, is_requesting?: false) client.instance_variable_set(:@worker, worker)