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

BlockingCache has a risk of OOM #1261

Closed
zhangweidavid opened this issue Apr 21, 2018 · 4 comments · Fixed by #2044
Closed

BlockingCache has a risk of OOM #1261

zhangweidavid opened this issue Apr 21, 2018 · 4 comments · Fixed by #2044

Comments

@zhangweidavid
Copy link
Contributor

Hi:

I think this class may has a risk of OOM .What do you think @harawata ?

https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/cache/decorators/BlockingCache.java

@harawata
Copy link
Member

Because entries in locks are never removed?
It seems to be possible, technically.

I found a SO thread discussing this exact subject.
https://stackoverflow.com/a/41912651
So, should we change BlockingCache to use CountDownLatch as proposed in the accepted answer?
Or do you have another idea?

@zhangweidavid
Copy link
Contributor Author

I think it's a good idea.

@kezhenxu94
Copy link
Contributor

It's a good idea but this may bring new bug when caching is enabled and continuous queries are called, here is my test case to reproduce it.

The problem is that the org.apache.ibatis.cache.decorators.TransactionalCache#putObject won't actually put the object to the delegated cache (BlockingCache here), causing the lock not to be released and later calls to getObject in the same thread blocked.

I don't know it's a bug of TransactionalCache or BlockingCache, I had open a PR #1358 to fix this bug based on the original implementation of BlockingCache, if we are to change BlockingCache to use CountDownLatch, how to deal with this bug? What do you think @harawata

harawata added a commit to harawata/mybatis-3 that referenced this issue Sep 6, 2020
harawata added a commit to harawata/mybatis-3 that referenced this issue Sep 6, 2020
harawata added a commit to harawata/mybatis-3 that referenced this issue Sep 6, 2020
@harawata
Copy link
Member

harawata commented Sep 6, 2020

I have submitted #2044 as a fix.
Let me know if you notice anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants