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
Potential race-condition in PojoTypes #2236
Comments
Thank you for reporting this - this definitely looks like a bug in Jdbi. |
Are you using Jdbi with multiple threads / are you moving handles between threads? Do you use a shared Jdbi with multiple threads? I can see a number of situations where multiple threads step on each others' toes. |
Yes. The application is a micronaut web server, where a singleton We have multiple thread pools and we pass My understand is that both jdbi and handle are considered thread-safe |
I did a little more digging and I was able to confirm that my framework lazily initializes singletons. We do our A work around is to do all app initialization eagerly |
little late on this (I took a break from Jdbi), but I do want to point you at http://jdbi.org/#_handle. The long and the short is: If you create a Handle or a Query object on a thread and then pass it off to another thread for execution, you should be fine (there may be obscure bugs lurking but I am fairly certain that all the main paths and the error paths are good). If you hold on to a handle, execute it on one thread and then do some manipulation on another, you are almost guaranteed to run into threading issues. |
Thank you - very good to know |
JDBI Version: 3.30.0
PojoTypes contains an internal map of factories which is copied in a number of situations, such as
Jdbi.open()
, or in my case when an on demand extension is used. This map is also modified by calls toregister
.Today, for the first time that I've noticed, calling a
@SqlBatch
annotated method on an on-demand extension threw a mysteriousConcurrentModificationException
, presumably because a factory was being registered at the same time thatPojoTypes.factory
was being copied (stacktrace below)The good news is that subsequent calls appear to work just fine.
I haven't yet tried to repro this because I have a feeling it will be very tricky, and I wanted some validation from people more familiar with the guts of JDBI before embarking on that road.
Alternatively, since this error implies
PojoTypes
is not thread-safe, I would be happy to write up a PR making it thread-safe without repro'ing if we like the risk-to-reward ratio.If I'm reading the following trace right, it implies that
other.factories
is being called concurrently - presumably because of a call topojoTypes.register
. I believe the bulk of my calls come fromJdbiImmutables.registerImmutable
and my framework ought to be making these calls during startup only, but I saw this exception regardless.The text was updated successfully, but these errors were encountered: