fix(org): resolve API handlers at request time to survive late plugin init - #9022
Merged
Merged
Conversation
… init Route registration can evaluate ApiResources() before InitPlugins() has run (InitPlugins is only invoked from pipelineServiceInit, which is delayed e.g. by a pending DB migration at boot). The org plugin returned bound method values on p.handlers, capturing a nil receiver permanently and making every org endpoint panic with a nil pointer dereference. Resolve p.handlers at request time via method expressions and return a clean error while the plugin is not initialized yet. Closes apache#9021
klesh
approved these changes
Jul 30, 2026
klesh
left a comment
Contributor
There was a problem hiding this comment.
LGTM.
Thanks for your contribution.
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
All
plugins/orgAPI endpoints (teams.csv,users.csv,user_account_mapping.csv,project_mapping.csv) panic with a nil pointer dereference whenever route registration wins the race against plugin initialization — full diagnosis with startup-log evidence in #9021.InitPlugins()(the only thing that callsPluginInit.Init()in server mode) runs insidepipelineServiceInit(), whileregisterPluginEndpointsevaluates each plugin'sApiResources()independently. The org plugin returned bound method values (p.handlers.GetTeam), and Go captures the receiver at evaluation time — ifInit()hasn't run yet, the router permanently holds handlers bound to a nil*Handlers. A pending DB migration at boot makes the bad ordering deterministic, which is why this bit several users after upgrades (#8590, #8271, #7957, #7219).This fix resolves
p.handlersat request time via method expressions, returning a clean 500 with "org plugin is not initialized yet, please retry later" during the (brief) pre-init window instead of panicking forever after it.go build/go vet/gofmtclean on the touched packagesTestApiResourcesBeforeInitFailsGracefullycovers every org endpoint pre-init (panicked before this change, clean error now)E2E_DB_URL)A broader alternative would be moving
InitPlugins()ahead of route registration in server startup — deliberately not done here to keep the change scoped to the affected plugin; happy to follow up if maintainers prefer that direction.Does this close any open issues?
Closes #9021