-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
Fix deadlock when starting #12659
Fix deadlock when starting #12659
Conversation
Codecov Report
@@ Coverage Diff @@
## 3.2 #12659 +/- ##
============================================
- Coverage 69.70% 66.89% -2.81%
+ Complexity 318 2 -316
============================================
Files 3481 1763 -1718
Lines 165010 70859 -94151
Branches 27726 10158 -17568
============================================
- Hits 115015 47403 -67612
+ Misses 40010 18881 -21129
+ Partials 9985 4575 -5410 see 2060 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
还有一种场景是在ApplicationListener 的 init 中调用 Dubbo,这个时候会报 |
@AlbumenJ 这个考虑合并不~ |
@@ -177,7 +182,7 @@ private void onContextClosedEvent(ContextClosedEvent event) { | |||
|
|||
@Override | |||
public int getOrder() { | |||
return LOWEST_PRECEDENCE; | |||
return LOWEST_PRECEDENCE - 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about change to HIGHEST_PRECEDENCE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提高到最高优先级也是可以的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead.
BTW, pls add some test cases to verify this PR.
c495c8d
to
fd7d7e0
Compare
Kudos, SonarCloud Quality Gate passed! |
@AlbumenJ 这个是否可以 |
3.1.x 的版本目前不会发布 bugfix 版本了,只有 security fix 了 |
Fix deadlock when starting (apache#12659)
What is the purpose of the change
fix #12620 线程死锁问题
@EnableScheduled
且在@Scheduled
注解修饰的方法中调用了dubbo
接口,如图中
spring
容器正常启动以后 发布了ContextRefreshedEvent
即会 先调用scheduleProcessor
再调用dubboDeployApplicationListener
(事件listener
如果没有配置单独的线程池异步执行(大部分情况应该都没配置),则是同步顺序执行的) ,就可能会出现 异步任务调用reference.get
获取了spring
单例锁(3.1.5 修改引入),dubboDeployApplicationListener
调用 deploy.start 获取了 dubbo 发布器锁, 此时如果 dubbo 存在 引用 懒加载的 spring bean 则会导致 死锁解决方式
1.1 提升
dubboDeployApplicationListener
优先级先于scheduleProcessor
处理。 (如果是listener 是配置了异步执行则无效)1.2 在
dubboDeployApplicationListener
调用 deploy 之前 先加 spring 单例锁 保证锁的获取顺序2.1 同步调用 此时可能存在 部分服务发布、订阅非预期 ,
2.2 异步调用 dubbo 启动过程中 可能存在部分服务发布、订阅非预期 或者同
@Scheduled
调度执行一样 造成死锁 可以通过deploy
加锁 进行排序加锁dubbo
接口,调用初始化入口为reference.get
和1 2 异步执行一样3.1.5
版本中 加了单例锁,所以修复 在 黄色 2 处也加单例锁Brief changelog
Verifying this change
Checklist