Skip to content

Fix "Finder with name 'xxx' is already registered" on plugin re-registration#9853

Merged
ruibaby merged 2 commits into
mainfrom
copilot/fix-finder-already-registered
Apr 7, 2026
Merged

Fix "Finder with name 'xxx' is already registered" on plugin re-registration#9853
ruibaby merged 2 commits into
mainfrom
copilot/fix-finder-already-registered

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

When a plugin's Spring context fires ContextRefreshedEvent (registering finders) but is then abandoned without a corresponding ContextClosedEvent — e.g., when finishRefresh() throws after the event, or when cleanup fails — the finder entries remain stale in DefaultFinderRegistry. The next start attempt (e.g., after a plugin upgrade) throws "Finder with name 'xxxFinder' is already registered", requiring a Halo restart to recover.

Fix: Call unregister(pluginId) at the top of register() to evict any stale entries for that plugin before registering new ones. This makes registration idempotent per plugin while still detecting genuine name conflicts across different plugins.

// DefaultFinderRegistry.register()
public void register(String pluginId, ApplicationContext pluginContext) {
    unregister(pluginId); // evict stale state before re-registering
    pluginContext.getBeansWithAnnotation(Finder.class)
        .forEach((beanName, finder) -> { ... });
}

Which issue(s) this PR fixes:

Fixes #9798

Special notes for your reviewer:

unregister() on an unknown pluginId is a no-op (map miss), so this adds zero overhead on normal first-time registration.

Does this PR introduce a user-facing change?

修复部分包含 Finder API 的插件可能在升级后无法正常启动的问题

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/working/files-to-index5977883620544843849.list --sourceArchiveDir=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/src --outputDir=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@f2c-ci-robot f2c-ci-robot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 7, 2026
Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
4 tasks
@f2c-ci-robot f2c-ci-robot Bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 7, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…isters finders

When a plugin's Spring context partially registers finders then fails (leaving
stale entries), subsequent start attempts throw "already registered". Fix by
calling unregister(pluginId) at the start of register() to clean up stale state.

Also adds tests for register/unregister plugin finders and the re-registration
scenario.

Agent-Logs-Url: https://github.com/halo-dev/halo/sessions/f07880fa-01f5-40a5-93cf-fc041187c3ed

Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Apr 7, 2026

Copy link
Copy Markdown

Copilot AI changed the title [WIP] Fix finder with name 'xxxFinder' is already registered Fix "Finder with name 'xxx' is already registered" on plugin re-registration Apr 7, 2026
@f2c-ci-robot f2c-ci-robot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 7, 2026
Copilot AI requested a review from ruibaby April 7, 2026 09:33
@ruibaby ruibaby marked this pull request as ready for review April 7, 2026 09:43
@f2c-ci-robot f2c-ci-robot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 7, 2026
@ruibaby ruibaby requested a review from JohnNiang April 7, 2026 09:59
@ruibaby ruibaby added this to the 2.24.x milestone Apr 7, 2026
@ruibaby

ruibaby commented Apr 7, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-2.23

@halo-dev-bot

Copy link
Copy Markdown
Contributor

@ruibaby: once the present PR merges, I will cherry-pick it on top of release-2.23 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-2.23

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ruibaby ruibaby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@f2c-ci-robot f2c-ci-robot Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 7, 2026
@f2c-ci-robot

f2c-ci-robot Bot commented Apr 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ruibaby

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 7, 2026
@ruibaby ruibaby merged commit d2b23fb into main Apr 7, 2026
14 of 17 checks passed
@ruibaby ruibaby deleted the copilot/fix-finder-already-registered branch April 7, 2026 10:43
@halo-dev-bot

Copy link
Copy Markdown
Contributor

@ruibaby: #9853 failed to apply on top of branch "release-2.23":

Patch is empty.
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To record the empty patch as an empty commit, run "git am --allow-empty".
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"

Details

In response to this:

/cherry-pick release-2.23

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ruibaby

ruibaby commented Apr 7, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-2.23

@halo-dev-bot

Copy link
Copy Markdown
Contributor

@ruibaby: #9853 failed to apply on top of branch "release-2.23":

Patch is empty.
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To record the empty patch as an empty commit, run "git am --allow-empty".
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"

Details

In response to this:

/cherry-pick release-2.23

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ruibaby

ruibaby commented Apr 9, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-2.23

@halo-dev-bot

Copy link
Copy Markdown
Contributor

@ruibaby: #9853 failed to apply on top of branch "release-2.23":

Patch is empty.
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To record the empty patch as an empty commit, run "git am --allow-empty".
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"

Details

In response to this:

/cherry-pick release-2.23

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

ruibaby added a commit to ruibaby/halo that referenced this pull request Apr 13, 2026
…tration (halo-dev#9853)

* Initial plan

* Fix "Finder with name 'xxx' is already registered" when plugin re-registers finders

When a plugin's Spring context partially registers finders then fails (leaving
stale entries), subsequent start attempts throw "already registered". Fix by
calling unregister(pluginId) at the start of register() to clean up stale state.

Also adds tests for register/unregister plugin finders and the re-registration
scenario.

Agent-Logs-Url: https://github.com/halo-dev/halo/sessions/f07880fa-01f5-40a5-93cf-fc041187c3ed

Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>
ruibaby added a commit that referenced this pull request Apr 13, 2026
…tration (#9853) (#9876)

* Initial plan

* Fix "Finder with name 'xxx' is already registered" when plugin re-registers finders

When a plugin's Spring context partially registers finders then fails (leaving
stale entries), subsequent start attempts throw "already registered". Fix by
calling unregister(pluginId) at the start of register() to clean up stale state.

Also adds tests for register/unregister plugin finders and the re-registration
scenario.

Agent-Logs-Url: https://github.com/halo-dev/halo/sessions/f07880fa-01f5-40a5-93cf-fc041187c3ed



---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>
@ruibaby ruibaby modified the milestones: 2.24.x, 2.24.0 Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finder with name 'xxxFinder' is already registered

4 participants