Skip to content
New issue

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

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

Already on GitHub? # to your account

fixed deadlock #1299

Merged
merged 1 commit into from
Jun 20, 2016
Merged

fixed deadlock #1299

merged 1 commit into from
Jun 20, 2016

Conversation

agapple
Copy link
Member

@agapple agapple commented Jun 17, 2016

两个线程:

  1. 线程A,在执行DruidDataSourceStatManager.reset()操作,会先拿到instances的锁,然后尝试去调用DruidDataSource.reset(),获取数据源的另一把锁
  2. 想成B,执行DruidDataSource.close(),获得了数据源的锁,然后尝试DruidDataSourceStatManager.removeDataSource(),尝试拿instances锁

两个线程就会出现死锁的情况,导致链接池无法正常工作.

解决办法:

  1. reset()方法,对于keyset()的遍历,没有那么强的同步要求,允许出现ConcurrentModificationException,去掉了线程A和B的instances锁
  2. 对于dataSources的IdentityHashMap加上同步方法,确保put/get/remove不会出现并发问题

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@wenshao wenshao merged commit b08480b into alibaba:master Jun 20, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants