Query with timer can throw IllegalThreadStateException#474
Query with timer can throw IllegalThreadStateException#474cheenamalhotra merged 2 commits intomicrosoft:devfrom maiken2051:master
Conversation
Running a query that uses a timer can cause an IllegalThreadStateException if the underlying ThreadGroup has been destroyed
Forgot to add AtomicReference
Codecov Report
@@ Coverage Diff @@
## dev #474 +/- ##
============================================
- Coverage 46.25% 46.21% -0.04%
+ Complexity 2206 2195 -11
============================================
Files 108 108
Lines 25231 25215 -16
Branches 4173 4166 -7
============================================
- Hits 11671 11654 -17
+ Misses 11541 11535 -6
- Partials 2019 2026 +7
Continue to review full report at Codecov.
|
|
@maiken2051 Thank you for your effort in creating this pr. Could you please open this to dev branch? |
|
Hi @maiken2051, I just rebased this against the dev branch. |
|
Thanks for rebasing the PR... |
|
@maiken2051, just wanted to keep you posted. We are going to be doing a code review soon. Thanks again for your contributions. |
|
Hi @maiken2051 Please sign CLA so that we can proceed with merging your PR. |
|
I think the CLA should be OK now? |
|
Hi @maiken2051, thanks for the contribution. The changes look good, and I approved it - but I'm curious as to where I can find the information regarding JVM destroying a ThreadGroup that contains no active threads. Could you point me to where I can read more about this? |
|
Check out the source for ThreadGroup.threadTerminated. This is from OpenJDK but I assume all JVM implementations are similar. The docs say:
When a thread exits it will call this method to remove itself from the active list on its owner ThreadGroup. If it's the last active thread the group will be destroyed. |
|
I see, thanks - please merge this pull request 👍 |
Running a query that uses a timer can cause an IllegalThreadStateException if the underlying ThreadGroup has been destroyed.
This error happens when the caller executes a query with a timeout and then doesn't execute another query with a timeout until some time has elapsed. The JVM can destroy the ThreadGroup behind the TimeoutTimer (because it contains no active threads) which causes any new query with a timeout to throw an IllegalThreadStateException.
Once the JDBC driver has entered this state any new query with a timeout will throw the exception. It's especially easy to run into this problem in demanding / multi-threaded applications.
My change makes sure the ThreadGroup is not destroyed before creating a new timer thread. If the ThreadGroup is destroyed, the code will create a new ThreadGroup.