Netflix / Hystrix

Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.
24.07k stars 4.7k forks source link

Changed ThreadPoolExecutor setCorePoolSize implementation on Java 10+ #1874

Open gergoistvannagy opened 5 years ago

gergoistvannagy commented 5 years ago

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

andystanton commented 5 years ago

Looks like it's Java 9+.

From the Java 8 API docs for ThreadPoolExecutor#setCorePoolSize:

Throws: IllegalArgumentException - if corePoolSize < 0

From the Java 9 API docs for ThreadPoolExecutor#setCorePoolSize:

Throws: IllegalArgumentException - if corePoolSize < 0 or corePoolSize 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)
DanieleCali commented 4 years ago

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.

Fival85 commented 4 years ago

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!

xinxin2015 commented 2 years ago

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?