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

使用静态部署方案启动基座时,如果基座依赖了OpenFeign,会在基座refresh context期间触发ContextRefreshedEvent,导致模块被提前部署,基座启动失败 #1032

Open
YanZhipeng-UESTC opened this issue Nov 21, 2024 · 6 comments
Labels

Comments

@YanZhipeng-UESTC
Copy link

YanZhipeng-UESTC commented Nov 21, 2024

通过将基座和模块合并打包的方式进行静态部署,基座项目使用OpenFeign远程调用模块,在基座应用执行到refreshContext时,FeignClient初始化会创建AnnotationConfigApplicationContext,并触发ContextRefreshedEvent事件,导致ArkDeployStaticBizListener消费事件后执行了模块的静态部署。由于此时基座还没有启动完成,导致最终基座的tomcat启动报错,端口被占用。
截屏2024-11-21 下午3 46 11

debug代码发现此异常场景ArkDeployStaticBizListener消费的事件的applicationContext对象的类型和正常部署场景下的不同。异常情况下的类型是AnnotationConfigApplicationContext
截屏2024-11-21 下午3 50 18

正常情况下context类型是AnnotationConfigServletWebServerApplicationContext
截屏2024-11-21 下午3 57 21

建议ArkDeployStaticBizListener在执行deployStaticBizAfterEmbedMasterBizStarted前增加applicationContext的类型判断,避免模块部署被提前执行。这是具体的修复方案
截屏2024-11-21 下午7 00 03
或者将消费的Event类型改为根StaticBatchInstallEventListener一样的ApplicationReadyEvent,并且加上重复部署的判断。

@YanZhipeng-UESTC
Copy link
Author

用官方的springboot-samples复现了这个场景,我发现如果只是加去重判断不能解决问题,因为模块和基座的tomcat启动都是有问题的。因为基座执行到ArkTomcatWebServer.start之前已经触发了模块的部署,并且模块会固定使用8080默认端口,模块部署成功后,基座执行ArkTomcatWebServer.start时会再次使用配置的8080端口创建连接,这时候报错端口已被占用。所以需要确保模块的部署不能出现在基座执行ArkTomcatWebServer.initialize和start之间
截屏2024-11-22 下午2 49 35
这里是基座报错端口占用的地方,正常情况下如果是后部署的模块这段代码是不会执行的,因为connectors是null

@xiaofc999
Copy link

模块和基座使用不同的端口呢, 我们的做法就是让的模块和基座使用不同端口

@YanZhipeng-UESTC
Copy link
Author

模块和基座使用不同的端口呢, 我们的做法就是让的模块和基座使用不同端口

使用不同的端口只是避免了端口冲突,但本质上还是不符合预期的,模块在部署的时候因为拿不到基座的tomcat启动信息,就会使用默认8080端口。虽然部署成功了,但是模块会触发二次部署,然后会报context path not unique的错误,你们没遇到这个错么

Copy link

This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue or help wanted) or other activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 26, 2024
Copy link

github-actions bot commented Jan 3, 2025

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue or help wanted. Thank you for your contributions.

@github-actions github-actions bot closed this as completed Jan 3, 2025
@gaosaroma gaosaroma reopened this Jan 3, 2025
Copy link

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue or help wanted. Thank you for your contributions.

@gaosaroma gaosaroma reopened this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants