fix: activate a plugin's hooks only after it has registered - #525
Open
abelonogov-ld wants to merge 4 commits into
Open
fix: activate a plugin's hooks only after it has registered#525abelonogov-ld wants to merge 4 commits into
abelonogov-ld wants to merge 4 commits into
Conversation
…arts Plugins could only be supplied through LDConfig, so an integration that learns about a plugin later — or that wants to instrument a client it did not configure — had no way in. Hooks were held in a constant array, which registration after start cannot extend, so they now live behind a lock and are replaced rather than mutated in place. Each series reads a snapshot once, so the hooks a series ends with are the hooks it began with: read again mid-series, a hook registered in between would be handed an "after" stage for a series whose "before" stage it was never in. Hooks go live only once register returns, matching the Android and .NET ordering, so a plugin's own hooks do not observe its register call. Retaining EnvironmentMetadata on the instance lets a plugin registered later be handed the same environment description as one configured up front, and removes the duplicate construction in start and collectHooks. Co-authored-by: Cursor <cursoragent@cursor.com>
* v11: feat: add registerPlugin so a plugin can be added after the client starts (#522) chore: pin the docs toolchain with a Gemfile so jazzy builds reproducibly (#523) # Conflicts: # LaunchDarkly/LaunchDarkly/LDClient.swift # LaunchDarkly/LaunchDarkly/LDClientIdentifyHook.swift # LaunchDarkly/LaunchDarklyTests/LDClientPluginsSpec.swift
Closed
4 tasks
Contributor
|
I don't understand the need for this change? I think this violates the intent of getHooks existing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #522. A plugin's hooks now go live only once every plugin has registered, and this applies to plugins in
LDConfig.pluginsand toregisterPluginalike, so a plugin behaves the same however it was registered.Previously
registerPluginactivated a plugin's hooks before callingregister, which meant a plugin's own hooks observed the evaluations and identify calls itsregistermade. Activating them last also means no plugin's hooks observe another plugin'sregister, rather than that depending on where the plugin sat in the list.Both paths now share one
registerPluginsmethod, so the two cannot drift apart again.Keeping plugin hooks in the initial identify
Activating hooks after
registeris only safe if registration still happens before the first identify series opens. On iOS it did not: the series began insideinit, whileplugin.registerran afterwards instart. Left alone, configured plugin hooks would have missed the initial identify entirely, sinceafterIdentifyreplays the snapshot taken atinit.So the tail of
initmoved intostartIdentifyAndGoOnline, andstartnow:LDClient.instances(so a plugin callingLDClient.get()fromregisterstill finds it),collectHooksis gone, sinceinitnow seeds only the configuration's own hooks.executeBeforeIdentifyHookstakes amethodNameso the startup path can reuse it rather than duplicating the series setup.Test plan
testPluginHooksFireDuringInitstill passes, confirming configured plugin hooks continue to take part in the initial identifytestRegisterPluginDoesNotRunTheRegisteringPluginsOwnHookscovers the new ordering for the runtime pathtestConfiguredPluginHooksDoNotObserveAnotherPluginsRegistercovers the cross-plugin caseNote
Overview
Plugin hooks now activate after each plugin’s
registerreturns, and only once all plugins in a batch have registered.registerPluginandLDConfig.pluginsboth use sharedregisterPlugins, so runtime and config-time registration behave the same: a plugin’s hooks no longer see its own (or another plugin’s) flag evaluations or identify calls made insideregister.Startup was reordered so configured plugin hooks still participate in the initial identify. The first identify / go-online work moved from
initintostartIdentifyAndGoOnline, andstartnow publishes the client toLDClient.instances, runsregisterPlugins, then opens that series.initseedsstoredHooksfrom config hooks only (collectHooksremoved).executeBeforeIdentifyHooksaccepts amethodNameso startup can label the series"init".Tests were updated for the new hook timing and add coverage that one configured plugin’s hooks do not run during another plugin’s
register.Reviewed by Cursor Bugbot for commit 4002fce. Bugbot is set up for automated code reviews on this repo. Configure here.