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

bugfix: fix deadlock during springboot project startup #2879

Merged
merged 44 commits into from
Nov 11, 2020

Conversation

wangliang181230
Copy link
Contributor

@wangliang181230 wangliang181230 commented Jul 10, 2020

Ⅰ. Describe what this PR did

修复springboot项目启动过程中的死锁问题。

目前碰到的死锁都是由main和timeoutChecker两个线程互锁造成的。

死锁有两种情况:

情况一:(注:这种情况已在1.4.0解决掉了 PR #3130

  1. 两个线程SpringBootConfigurationProvider获取property bean时spring的DefaultSingletonBeanRegistry.getSingleton()方法
  2. main线程在项目启动过程中触发了AT模式的代理,并在执行代理初始化方法时执行了seata服务发现功能并调用了RegistryFactory.getInstance()
  3. timeoutChecker线程reconnect时,也调用了RegistryFactory.getInstance()
    导致两个线程互锁了。

情况二:

  1. 两个线程SpringBootConfigurationProvider获取property bean时spring的DefaultSingletonBeanRegistry.getSingleton()方法
  2. main线程初始化TM或RM时创建与server的连接时调用的NettyClientChannelManager.acquireChannel()方法
  3. timeoutChecker线程reconnect时也调用NettyClientChannelManager.acquireChannel()
    导致两个线程互锁了。

为了避免以上两种死锁,以及其他未知的死锁情况,此PR改动了以下内容:

seata相关的配置bean的创建优先于其他所有seata的bean,并提前设置到PROPERTY_BEAN_MAP中,让其他线程在获取配置时,无需再调用DefaultSingletonBeanRegistry.getSingleton()方法,直接从PROPERTY_BEAN_MAP中获取,以此避免死锁。

拆分此PR

#3130 bugfix: fix some problems in the automatic data source proxy.

Ⅱ. Does this pull request fix one issue?

fixes #2857
fixes #2960 顺便解决此issue

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2020

Codecov Report

Merging #2879 into develop will decrease coverage by 0.15%.
The diff coverage is 13.88%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #2879      +/-   ##
=============================================
- Coverage      50.46%   50.30%   -0.16%     
+ Complexity      3111     3107       -4     
=============================================
  Files            593      593              
  Lines          19571    19571              
  Branches        2427     2428       +1     
=============================================
- Hits            9876     9845      -31     
- Misses          8702     8731      +29     
- Partials         993      995       +2     
Impacted Files Coverage Δ Complexity Δ
...ing/boot/autoconfigure/SeataAutoConfiguration.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...gure/provider/SpringBootConfigurationProvider.java 38.88% <50.00%> (-6.57%) 8.00 <2.00> (-1.00)
...ta/spring/boot/autoconfigure/StarterConstants.java 100.00% <100.00%> (ø) 1.00 <1.00> (ø)
...o/seata/server/coordinator/DefaultCoordinator.java 54.63% <0.00%> (-0.52%) 28.00% <0.00%> (-2.00%)
...in/java/io/seata/server/session/GlobalSession.java 82.43% <0.00%> (-0.46%) 70.00% <0.00%> (-1.00%)

@l81893521 l81893521 added the module/seata-spring-boot-starter seata-spring-boot-starter module label Jul 16, 2020
Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

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

Good job.I left a comment.

Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

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

LGTM.

…eadlock

# Conflicts:
#	spring/src/main/java/io/seata/spring/annotation/datasource/SeataAutoDataSourceProxyAdvice.java
wangliang181230 and others added 6 commits September 18, 2020 12:24
…eadlock

# Conflicts:
#	seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java
…eadlock

# Conflicts:
#	seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java
@codecov-io
Copy link

codecov-io commented Oct 10, 2020

Codecov Report

Merging #2879 (a232009) into develop (69f341a) will decrease coverage by 0.15%.
The diff coverage is 13.15%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #2879      +/-   ##
=============================================
- Coverage      51.02%   50.86%   -0.16%     
+ Complexity      3279     3278       -1     
=============================================
  Files            612      612              
  Lines          20114    20113       -1     
  Branches        2518     2519       +1     
=============================================
- Hits           10263    10231      -32     
- Misses          8822     8853      +31     
  Partials        1029     1029              
Impacted Files Coverage Δ Complexity Δ
...ing/boot/autoconfigure/SeataAutoConfiguration.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...gure/provider/SpringBootConfigurationProvider.java 38.88% <50.00%> (-6.57%) 8.00 <2.00> (-1.00)
...ta/spring/boot/autoconfigure/StarterConstants.java 100.00% <100.00%> (ø) 1.00 <1.00> (ø)

jsbxyyx and others added 6 commits October 12, 2020 10:09
…eadlock

# Conflicts:
#	seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java
…eadlock

# Conflicts:
#	seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java
@wangliang181230 wangliang181230 added this to the 1.5.0 milestone Oct 29, 2020
@funky-eyes funky-eyes mentioned this pull request Nov 11, 2020
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/seata-spring-boot-starter seata-spring-boot-starter module
Projects
None yet
7 participants