Skip to content

fix(org): resolve API handlers at request time to survive late plugin init - #9022

Merged
klesh merged 1 commit into
apache:mainfrom
pballester:fix/org-api-handlers-nil-race
Jul 30, 2026
Merged

fix(org): resolve API handlers at request time to survive late plugin init#9022
klesh merged 1 commit into
apache:mainfrom
pballester:fix/org-api-handlers-nil-race

Conversation

@pballester

Copy link
Copy Markdown

Summary

All plugins/org API 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 calls PluginInit.Init() in server mode) runs inside pipelineServiceInit(), while registerPluginEndpoints evaluates each plugin's ApiResources() independently. The org plugin returned bound method values (p.handlers.GetTeam), and Go captures the receiver at evaluation time — if Init() 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.handlers at 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 / gofmt clean on the touched packages
  • New unit test TestApiResourcesBeforeInitFailsGracefully covers every org endpoint pre-init (panicked before this change, clean error now)
  • e2e tests unchanged (require 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

… 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 klesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks for your contribution.

@klesh
klesh merged commit 2d4834c into apache:main Jul 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][org] All org plugin API endpoints panic with nil pointer — root cause: routes bind handlers before InitPlugins runs

2 participants