Hystrix
Hystrix copied to clipboard
Changed ThreadPoolExecutor setCorePoolSize implementation on Java 10+
On OpenJdk 11 the implementation of ThreadPoolExecutor's setCorePoolSize was changed and contains an additional constraints comparing the maxPoolSize and corePoolSize values.
If maxPoolSize is not changed but corePoolSize is given as a higher number of default maxPoolSize it throws IllegalArgumentException.
This causes issue here: https://github.com/Netflix/Hystrix/blob/master/hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPool.java#L230-L231
Looks like it's Java 9+.
From the Java 8 API docs for ThreadPoolExecutor#setCorePoolSize:
Throws:
IllegalArgumentException
- ifcorePoolSize < 0
From the Java 9 API docs for ThreadPoolExecutor#setCorePoolSize:
Throws:
IllegalArgumentException
- ifcorePoolSize < 0
orcorePoolSize
is greater than the maximum pool size
Here's a minimal example - it can be triggered if the core size is changed through Archaius:
@Test
void simplestTest() throws Exception {
var command = new HystrixCommand<>(HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("Group"))
.andCommandKey(HystrixCommandKey.Factory.asKey("Command"))) {
@Override
protected String run() throws Exception {
return null;
}
};
// ConfigurationManager is from Archaius
ConfigurationManager.getConfigInstance().setProperty("hystrix.threadpool.Group.coreSize", 11);
command.execute();
}
This exception is thrown when the command is executed:
com.netflix.hystrix.exception.HystrixRuntimeException: Command failed while executing.
...
Caused by: java.lang.IllegalArgumentException
at java.base/java.util.concurrent.ThreadPoolExecutor.setCorePoolSize(ThreadPoolExecutor.java:1535)
at com.netflix.hystrix.HystrixThreadPool$HystrixThreadPoolDefault.touchConfig(HystrixThreadPool.java:230)
at com.netflix.hystrix.HystrixThreadPool$HystrixThreadPoolDefault.getScheduler(HystrixThreadPool.java:205)
The Hystrix documentation here: https://github.com/Netflix/Hystrix/wiki/Configuration#maximumSize it says you can't modify the maximumSize hystrix property if you don't set the allowMaximumSizeToDivergeFromCoreSize to true. setting this property to true you are able to have different values for the core pool size and the maximum pool size.
The issue appears also when you set the coresize greater then the default maximum size, because of a failed implementation of the HystrixThreadPool class. The error appears, because firstly the core size is set and after this the maximus size of the threadpool. At the moment when the core size is set and it is bigger then the default size (10) the IllegalArgumentException is thrown.
In this case you could set allowMaximumSizeToDivergeFromCoreSize as you like. It doesnt fix the error!
I meet this issue also,but how can I replay this issue,no one would write 'ConfigurationManager.getConfigInstance().setProperty("hystrix.threadpool.Group.coreSize", 11);' such code in application,anywhere interface to modify the properties?