Hystrix icon indicating copy to clipboard operation
Hystrix copied to clipboard

Changed ThreadPoolExecutor setCorePoolSize implementation on Java 10+

Open gergoistvannagy opened this issue 6 years ago • 4 comments

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

gergoistvannagy avatar Oct 27 '18 21:10 gergoistvannagy

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)

andystanton avatar Nov 08 '18 14:11 andystanton

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.

DanieleCali avatar Jan 10 '20 10:01 DanieleCali

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!

Fival85 avatar May 20 '20 11:05 Fival85

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?

xinxin2015 avatar May 26 '22 02:05 xinxin2015