alibaba/Sentinel · error · IllegalStateException

Invalid Value for Read Timeout set.

Error message

Invalid Value for Read Timeout set.

What it means

Thrown by SentinelRuleLocator.getSecureRestTemplate() when the configured request read timeout is negative. The value is taken from the config client properties (spring.cloud.config.request-read-timeout) and passed straight to SimpleClientHttpRequestFactory.setReadTimeout, so Sentinel rejects negatives before building the RestTemplate used to call the Config Server.

Source

Thrown at sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SentinelRuleLocator.java:239

                    continue;
                }
            }

            if (response == null || response.getStatusCode() != HttpStatus.OK) {
                return null;
            }

            Environment result = response.getBody();
            return result;
        }

        return null;
    }

    private RestTemplate getSecureRestTemplate(ConfigClientProperties client) {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        if (client.getRequestReadTimeout() < 0) {
            throw new IllegalStateException("Invalid Value for Read Timeout set.");
        }
        requestFactory.setReadTimeout(client.getRequestReadTimeout());
        RestTemplate template = new RestTemplate(requestFactory);
        Map<String, String> headers = new HashMap<>(client.getHeaders());
        if (headers.containsKey(AUTHORIZATION)) {
            // To avoid redundant addition of header
            headers.remove(AUTHORIZATION);
        }
        if (!headers.isEmpty()) {
            template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
                new GenericRequestHeaderInterceptor(headers)));
        }

        return template;
    }

    private void addAuthorizationToken(ConfigClientProperties configClientProperties,
                                       HttpHeaders httpHeaders, String username, String password) {

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Set a non-negative timeout in milliseconds, e.g. spring.cloud.config.request-read-timeout: 60000 (0 means no/infinite timeout for the underlying factory).
  2. Search the config (including environment variables and bootstrap.yml) for negative timeout values and fix them.
  3. If the value is computed, clamp it: Math.max(0, configuredTimeout).

Example fix

# before
spring.cloud.config.request-read-timeout: -1

# after
spring.cloud.config.request-read-timeout: 60000
Defensive patterns

Strategy: validation

Validate before calling

int readTimeout = Math.max(0, configuredReadTimeoutMs); // clamp before it reaches the client
System.setProperty("spring.cloud.config.request-read-timeout", String.valueOf(readTimeout));

Try / catch

try {
    locator.locate(environment);
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().contains("Read Timeout")) {
        throw new IllegalStateException("request-read-timeout must be >= 0 ms; fix config", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Setting spring.cloud.config.request-read-timeout (or the sentinel-rule-source equivalent) to a negative number, e.g. -1 intended as 'infinite' but interpreted literally; a computed timeout property that can go negative under some configs.

Common situations: Someone ports '-1 means no timeout' semantics from another HTTP client; property defined via an expression that evaluates negative; copy-pasted example values. The failure occurs at locator initialization, so the app fails at startup.

Understand the failure class

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/4e4a719c58ed0f39. Report an issue: GitHub.