Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize schemes before refreshing application context #5032

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

JohnNiang
Copy link
Member

What type of PR is this?

/kind improvement
/area core

What this PR does / why we need it:

Prior to this proposal, we encountered an error requesting any page before Halo is in ready state. That is because the timing of schemes initialization is incorrect.

The current proposal is to advance schemes initialization before refreshing application and removes SchemeInitializedEvent because it cannot be listened by other beans.

Which issue(s) this PR fixes:

Fixes #4946

Special notes for your reviewer:

Does this PR introduce a user-facing change?

修复 Halo 还未处于准备就绪时访问页面或接口出现“Scheme not found”错误的问题

Signed-off-by: John Niang <johnniang@foxmail.com>
@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. kind/improvement Categorizes issue or PR as related to a improvement. labels Dec 11, 2023
@f2c-ci-robot f2c-ci-robot bot requested review from minliacom and wan92hen December 11, 2023 08:54
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Dec 11, 2023
@JohnNiang JohnNiang added this to the 2.12.x milestone Dec 11, 2023
Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (8b405fa) 55.94% compared to head (3debc6e) 55.94%.
Report is 1 commits behind head on main.

Files Patch % Lines
...app/theme/router/ThemeCompositeRouterFunction.java 0.00% 2 Missing ⚠️
...n/halo/app/infra/ExtensionResourceInitializer.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5032   +/-   ##
=========================================
  Coverage     55.94%   55.94%           
+ Complexity     3034     3032    -2     
=========================================
  Files           525      524    -1     
  Lines         17816    17817    +1     
  Branches       1329     1328    -1     
=========================================
+ Hits           9967     9968    +1     
  Misses         7300     7300           
  Partials        549      549           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

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

卸载插件时会出现

image

@JohnNiang
Copy link
Member Author

Hi @guqing ,建议提供完整的错误日志。(发现错误日志前面有一个 Warning)。

@guqing
Copy link
Member

guqing commented Dec 13, 2023

Hi @guqing ,建议提供完整的错误日志。(发现错误日志前面有一个 Warning)。

几乎都是可以复现的,我尝试了两次不同的插件出现这个问题,可以尝试安装两到三个插件然后挨个卸载(不要等一个卸载完在卸载另一个)

日志如下

2023-12-13T11:08:47.518+08:00 DEBUG 93729 --- [yReconciler-t-1] .a.p.r.ReverseProxyRouterFunctionFactory : Plugin [PluginMoments] registered reverse proxy route path [/plugins/PluginMoments/assets/logo.svg]
2023-12-13T11:08:47.532+08:00 DEBUG 93729 --- [yReconciler-t-1] .a.p.r.ReverseProxyRouterFunctionFactory : Plugin [PluginMoments] registered reverse proxy route path [/plugins/PluginMoments/assets/logo.svg]
2023-12-13T11:08:47.574+08:00  INFO 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Stop plugin 'PluginMoments@1.0.1-SNAPSHOT'
2023-12-13T11:08:47.574+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.SpringComponentsFinder    : Removing components storage from cache [PluginMoments].
2023-12-13T11:08:47.574+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.PluginApplicationContext  : Closing run.halo.app.plugin.PluginApplicationContext@76d5fa87, started on Wed Dec 13 11:08:39 CST 2023, parent: run.halo.app.plugin.SharedApplicationContext@43b54b12
2023-12-13T11:08:48.224+08:00 DEBUG 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Already stopped plugin 'PluginMoments@1.0.1-SNAPSHOT'
2023-12-13T11:08:48.224+08:00 DEBUG 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Already stopped plugin 'PluginMoments@1.0.1-SNAPSHOT'
2023-12-13T11:08:48.224+08:00  INFO 93729 --- [nReconciler-t-1] org.pf4j.AbstractPluginManager           : Unload plugin 'PluginMoments@1.0.1-SNAPSHOT'
2023-12-13T11:08:55.487+08:00 DEBUG 93729 --- [yReconciler-t-1] .a.p.r.ReverseProxyRouterFunctionFactory : Plugin [PluginLinks] registered reverse proxy route path [/plugins/PluginLinks/assets/logo.png]
2023-12-13T11:08:55.488+08:00  INFO 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Stop plugin 'PluginLinks@1.2.0-SNAPSHOT'
2023-12-13T11:08:55.488+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.SpringComponentsFinder    : Removing components storage from cache [PluginLinks].
2023-12-13T11:08:55.488+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.PluginApplicationContext  : Closing run.halo.app.plugin.PluginApplicationContext@15543aa2, started on Wed Dec 13 11:07:45 CST 2023, parent: run.halo.app.plugin.SharedApplicationContext@43b54b12
2023-12-13T11:08:55.513+08:00 DEBUG 93729 --- [yReconciler-t-1] .a.p.r.ReverseProxyRouterFunctionFactory : Plugin [PluginLinks] registered reverse proxy route path [/plugins/PluginLinks/assets/logo.png]
2023-12-13T11:08:56.155+08:00 DEBUG 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Already stopped plugin 'PluginLinks@1.2.0-SNAPSHOT'
2023-12-13T11:08:56.155+08:00 DEBUG 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Already stopped plugin 'PluginLinks@1.2.0-SNAPSHOT'
2023-12-13T11:08:56.155+08:00  INFO 93729 --- [nReconciler-t-1] org.pf4j.AbstractPluginManager           : Unload plugin 'PluginLinks@1.2.0-SNAPSHOT'
2023-12-13T11:09:00.523+08:00  INFO 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Stop plugin 'app-store@1.0.0-SNAPSHOT'
2023-12-13T11:09:00.524+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.SpringComponentsFinder    : Removing components storage from cache [app-store].
2023-12-13T11:09:00.524+08:00 DEBUG 93729 --- [nReconciler-t-1] r.h.app.plugin.PluginApplicationContext  : Closing run.halo.app.plugin.PluginApplicationContext@3d77ac15, started on Wed Dec 13 11:07:44 CST 2023, parent: run.halo.app.plugin.SharedApplicationContext@43b54b12
2023-12-13T11:09:00.534+08:00  WARN 93729 --- [nReconciler-t-1] r.h.a.e.controller.DefaultController     : Optimistic locking failure when reconciling request: run.halo.app.core.extension.reconciler.PluginReconciler-worker-1/Request[name=app-store]
2023-12-13T11:09:01.155+08:00  INFO 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Stop plugin 'app-store@1.0.0-SNAPSHOT'
2023-12-13T11:09:01.155+08:00 ERROR 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : 500 INTERNAL_SERVER_ERROR "Scheme not found for store.halo.run/v1alpha1/Application"

run.halo.app.extension.exception.SchemeNotFoundException: 500 INTERNAL_SERVER_ERROR "Scheme not found for store.halo.run/v1alpha1/Application"
	at run.halo.app.extension.SchemeManager.lambda$get$1(SchemeManager.java:43) ~[classes/:na]
	at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
	at run.halo.app.extension.SchemeManager.get(SchemeManager.java:42) ~[classes/:na]
	at run.halo.app.extension.SchemeManager.get(SchemeManager.java:49) ~[classes/:na]
	at run.halo.store.StorePlugin.stop(StorePlugin.java:147) ~[na:na]
	at run.halo.app.plugin.HaloPluginManager.stopPlugin(HaloPluginManager.java:159) ~[classes/:na]
	at run.halo.app.plugin.HaloPluginManager.stopPlugin(HaloPluginManager.java:179) ~[classes/:na]
	at org.pf4j.AbstractPluginManager.deletePlugin(AbstractPluginManager.java:325) ~[pf4j-3.10.0.jar:3.10.0]
	at run.halo.app.core.extension.reconciler.PluginReconciler.cleanUpResources(PluginReconciler.java:759) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$cleanUpResourcesAndRemoveFinalizer$25(PluginReconciler.java:720) ~[classes/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.cleanUpResourcesAndRemoveFinalizer(PluginReconciler.java:719) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$reconcile$0(PluginReconciler.java:102) ~[classes/:na]
	at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:100) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:82) ~[classes/:na]
	at run.halo.app.extension.controller.DefaultController$Worker.run(DefaultController.java:163) ~[classes/:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2023-12-13T11:09:01.156+08:00  INFO 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Stop plugin 'app-store@1.0.0-SNAPSHOT'
2023-12-13T11:09:01.157+08:00 ERROR 93729 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : 500 INTERNAL_SERVER_ERROR "Scheme not found for store.halo.run/v1alpha1/Application"

run.halo.app.extension.exception.SchemeNotFoundException: 500 INTERNAL_SERVER_ERROR "Scheme not found for store.halo.run/v1alpha1/Application"
	at run.halo.app.extension.SchemeManager.lambda$get$1(SchemeManager.java:43) ~[classes/:na]
	at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
	at run.halo.app.extension.SchemeManager.get(SchemeManager.java:42) ~[classes/:na]
	at run.halo.app.extension.SchemeManager.get(SchemeManager.java:49) ~[classes/:na]
	at run.halo.store.StorePlugin.stop(StorePlugin.java:147) ~[na:na]
	at run.halo.app.plugin.HaloPluginManager.stopPlugin(HaloPluginManager.java:159) ~[classes/:na]
	at org.pf4j.AbstractPluginManager.unloadPlugin(AbstractPluginManager.java:284) ~[pf4j-3.10.0.jar:3.10.0]
	at org.pf4j.AbstractPluginManager.unloadPlugin(AbstractPluginManager.java:270) ~[pf4j-3.10.0.jar:3.10.0]
	at org.pf4j.AbstractPluginManager.deletePlugin(AbstractPluginManager.java:335) ~[pf4j-3.10.0.jar:3.10.0]
	at run.halo.app.core.extension.reconciler.PluginReconciler.cleanUpResources(PluginReconciler.java:759) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$cleanUpResourcesAndRemoveFinalizer$25(PluginReconciler.java:720) ~[classes/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.cleanUpResourcesAndRemoveFinalizer(PluginReconciler.java:719) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$reconcile$0(PluginReconciler.java:102) ~[classes/:na]
	at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:100) ~[classes/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:82) ~[classes/:na]
	at run.halo.app.extension.controller.DefaultController$Worker.run(DefaultController.java:163) ~[classes/:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2023-12-13T11:09:01.158+08:00  INFO 93729 --- [nReconciler-t-1] org.pf4j.AbstractPluginManager           : Unload plugin 'app-store@1.0.0-SNAPSHOT'

@JohnNiang
Copy link
Member Author

从日志中可以看到,卸载插件过程中出现了“Optimistic locking failure”错误,导致重复调用 stop 方法。

当前 PR 的修改,应该是不会影响到插件的卸载流程。而且,我在本地多次测试插件(stop 方法中同样调用了 schemeManager#unregister 方法)卸载,都没有问题。

@JohnNiang
Copy link
Member Author

因插件中 stop 方法可能会被多次调用,建议通过以下方式 unregister scheme:

- schemeManager.unregister(schemeManager.get(Synchronization.class));
+ schemeManager.unregister(Scheme.buildFromType(Synchronization.class));

Copy link
Member

@guqing guqing left a comment

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 Dec 13, 2023
Copy link

f2c-ci-robot bot commented Dec 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guqing

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

The pull request process is described here

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 Dec 13, 2023
@f2c-ci-robot f2c-ci-robot bot merged commit d777dbf into halo-dev:main Dec 13, 2023
4 checks passed
@JohnNiang JohnNiang deleted the refactor/initialize-schemes branch December 13, 2023 06:52
@JohnNiang JohnNiang modified the milestones: 2.12.x, 2.12.0 Jan 7, 2024
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. area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement. 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.

【偶发】通过 Docker Compose 启动可能会出现 Scheme not found 错误
2 participants