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
HikariPool - fix major bug with usage of com.zaxxer.hikari.blockUntilFilled in JDK 11 and later #1605
HikariPool - fix major bug with usage of com.zaxxer.hikari.blockUntilFilled in JDK 11 and later #1605
Conversation
…mumPoolSize needs to be done before setCorePoolSize, the current implementation throws IllegalArgumentException and hence prefilling of connections by setting com.zaxxer.hikari.blockUntilFilled is broken.
Codecov Report
@@ Coverage Diff @@
## dev #1605 +/- ##
=========================================
Coverage 70.11% 70.11%
Complexity 561 561
=========================================
Files 26 26
Lines 2118 2118
Branches 296 296
=========================================
Hits 1485 1485
Misses 487 487
Partials 146 146
Continue to review full report at Codecov.
|
@brettwooldridge this looks like a blocker for those wishing to adopt jdk 11. |
I don't think this is correct, |
@pentlander please provide the stracktrace. |
Well logically once line 149 is reached, the core size and max size are at least 16. Once you try to shrink the max size to 1, this line gets run and fails because the core size is still 16. I'll attach a stacktrace tomorrow morning. |
Using Hikari 4.0.1 with OpenJDK 15, with "com.zaxxer.hikari.blockUntilFilled" set to true and initialization fail timeout at 10_000:
|
wow looks like we need some conditional checks when setting the value to avoid the iae.
|
It should be fine if 149 and 150 are flipped back to their original order, i.e.
|
Wait. Are we saying that in JDK 11 we need to call |
No, I'm saying that the new code increasing the pool size is correct here because it increases the max size to 16 before increasing the core size, avoiding this condition:
The new code is incorrect here because it is reducing the max pool size to 1 while the core pool size is still 16, thus triggering:
If the latter code is reverted to this it should work, since the the core size will always be less than the max size:
I don't know why the author of the pull request didn't run into this issue, the JDK11 checks are the same as the JDK15 ones: https://github.com/openjdk/jdk11/blob/37115c8ea4aff13a8148ee2b8832b20888a5d880/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java#L1658 |
…or pool sizes back to defaults, the core pool size must be changed before the maximum pool size.
Fixed and released as v4.0.2. |
I validated it's working with JDK15. Thanks! |
Due to a change in JDK11 in ThreadPoolExecutor setMaximumPoolSize needs to be done before setCorePoolSize, the current implementation throws IllegalArgumentException and hence prefilling of connections by setting com.zaxxer.hikari.blockUntilFilled is broken.
HikariPool -line 133 - addConnectionExecutor initializes the ThreadPoolExecutor with 1 core and 1 max thread.
Then we get an IllegalArgumentException in line 141while trying to set setCorePoolSize due to check
NOTE: This bug and PR was submitted by some other developers in the past I think, but it's still not fixed.
if (corePoolSize < 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException();
1 < some number of core pools make it throw IllegalArgumentException
Hence setting "com.zaxxer.hikari.blockUntilFilled " to true and trying to prefill connections fails.
This feature was working fine in JDK 8. Kindly review and merge this pull request.