-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Sometimes getMapper exception #2890
Comments
Can you try latest? Typically we don't have resources to figure out old versions and if item was previously reported it could already be fixed.
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: uniquewings ***@***.***>
Sent: Tuesday, June 20, 2023 4:36:01 AM
To: mybatis/mybatis-3 ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [mybatis/mybatis-3] Sometimes getMapper exception (Issue #2890)
MyBatis version
3.5.9
Test case or example project
We have an application, it will start a grpc server, will load all mapper at main thread, and will receive business task from grpc client in grpc thread pool. We sometimes get the exception "Type xxx is not known to the MapperRegistry", but when we check the appliction log, we are confused why the exception will occur.
1. first, we use sqlSessionTemplate.getConfiguration().addMapper(mapper); to add all the mappers. (main thread)
2. then we use sqlSessionTemplate.getConfiguration().hasMapper(mapper); to check if the mapper add success.(main thread)
3. last we will will wait mapper load finished by step1 and step 2, and then use sessionTemplate.getMapper(mapper); to get the mapper to use.(grpc thread pool)
As we check the code of MapperRegistry, when addMapper end, there's no way to remove mapper from the knownMappers. How did the exception occur when getMapper at step 3.
We expect getMapper success everytime at step 3.
—
Reply to this email directly, view it on GitHub<#2890>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHODI5SB3AM7AHCOHUK64LXMFOHDANCNFSM6AAAAAAZM5UIOM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
We will not update to the latest version recently. I don't think it has already be fixed. The use of mybatis in our application has such details:
In application log, the hasMapper return true before the exception when call sessionTemplate.getMapper. |
Please try the latest version. |
#2709 seems like fix the race condition of Mapped Statements, but not fix the race condition of mapper. The knownMappers define in MapperRegistry has the same problem. When one thread addMapper for new mapper and reach resize of HashMap, another thread try to get a mapper that has been added already may return null. public class MapperRegistry { |
any progress? |
It is unclear whether you actually tried the latest version or not, but if the problem reproduces with the latest version, I have no idea why. If the steps you posted are accurate, it is technically impossible, right? |
Why it is technically impossible? For example:
|
Ah, I'm sorry I didn't read your comment correctly. So, your problem will be resolved if MyBatis uses |
Yes, just like the #2709 use ConcurrentHashMap for StrictMap. |
@uniquewings Is this something you can raise a pull request for? |
…le other threads calling addMapper fix the issue 2890: mybatis#2890
Hi, @uniquewings see my comment on the PR. I did merge it but not 100% that solves it for you. I don't see anything wrong with doing that and your situation sounds rather unique. If you could give it a try and let us know if that fixes it. I don't recall all the specifics on the original fix we had elsewhere but seemed like that extra bit was needed that you didn't add. I don't know if that is really necessary or not given the use case. Anyway, we publish to sonatype snapshots so you can pull there or just use your own build to try to see if that resolves it. Not sure when our next release will be but its probably sometime in near future. |
MyBatis version
3.5.9
Test case or example project
We have an application, it will start a grpc server, will load all mapper at main thread, and will receive business task from grpc client in grpc thread pool. We sometimes get the exception "Type xxx is not known to the MapperRegistry", but when we check the appliction log, we are confused why the exception will occur.
As we check the code of MapperRegistry, when addMapper end, there's no way to remove mapper from the knownMappers. How did the exception occur when getMapper at step 3.
We expect getMapper success everytime at step 3.
The text was updated successfully, but these errors were encountered: