sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.92k stars 1.26k forks source link

SOFAArk module uninstall 报错,无法正常完成清理工作 #1321

Closed lvjing2 closed 1 month ago

lvjing2 commented 1 month ago

Describe the bug

模块卸载时,会执行两个步骤:

  1. 执行 applicationContext.close() 操作,这会清理 SOFARuntimeContainer 里的模块 SOFARuntime
  2. 执行 com.alipay.sofa.boot.ark.handler.SofaBizUninstallEventHandler,会执行清理操作,但是由于 SOFARuntime 已经在第一步里被删除了,所以这一步的清理实际上没有完成,而直接报错。 image

To Reproduce

Steps to reproduce the behavior:

  1. 打开 https://github.com/koupleless/samples/tree/main/sofaboot4-samples/dynamic-stock
  2. 启动基座,并安装模块
  3. 卸载模块
  4. 报错 image

Expected behavior

无报错,正常卸载模块

Environment:

CrazyHZM commented 1 month ago

@lvjing2 看了一下是因为BizUninstallEventHandler 执行了shutdownContext,这边要执行shutdownContext的原因是什么?

lvjing2 commented 1 month ago

@CrazyHZM BizUninstallEventHandler 是触发模块 application Context真正执行 close 操作的地方,模块卸载的真正操作就在这里面完成的

lvjing2 commented 1 month ago

sofaboot 4的基座 + sofaboot 4的模块,就会发生这个问题

HzjNeverStop commented 1 month ago

SOFAArk 模块卸载时是否能只触发 BeforeBizStopEvent,不要主动调用 applicationContext.close() 方法呢,在 com.alipay.sofa.runtime.spi.component.SofaRuntimeManager#shutDownExternally 的后续逻辑中会执行 applicationContext.close()

CrazyHZM commented 1 month ago

@lvjing2 context的生命周期可以交给sofaboot管理,ark可以不关心context是什么阶段销毁的。看看主动执行shutdownContext是有什么特殊场景吗

lvjing2 commented 1 month ago

sofaark 面向sofaboot 和 springboot等多种框架,如果这样,其他框架的模块就没有自动关闭的能力

CrazyHZM commented 1 month ago

sofaark 面向sofaboot 和 springboot等多种框架,如果这样,其他框架的模块就没有自动关闭的能力

同意,sofaboot这边需要再destroy的时候加强一下生命周期的管理,能够支持application context close时销毁相关对象。