{"record":{"id":"4e4a719c58ed0f39","repo":"alibaba/Sentinel","slug":"invalid-value-for-read-timeout-set","errorCode":null,"errorMessage":"Invalid Value for Read Timeout set.","messagePattern":"Invalid Value for Read Timeout set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SentinelRuleLocator.java","lineNumber":239,"sourceCode":"                    continue;\n                }\n            }\n\n            if (response == null || response.getStatusCode() != HttpStatus.OK) {\n                return null;\n            }\n\n            Environment result = response.getBody();\n            return result;\n        }\n\n        return null;\n    }\n\n    private RestTemplate getSecureRestTemplate(ConfigClientProperties client) {\n        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();\n        if (client.getRequestReadTimeout() < 0) {\n            throw new IllegalStateException(\"Invalid Value for Read Timeout set.\");\n        }\n        requestFactory.setReadTimeout(client.getRequestReadTimeout());\n        RestTemplate template = new RestTemplate(requestFactory);\n        Map<String, String> headers = new HashMap<>(client.getHeaders());\n        if (headers.containsKey(AUTHORIZATION)) {\n            // To avoid redundant addition of header\n            headers.remove(AUTHORIZATION);\n        }\n        if (!headers.isEmpty()) {\n            template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(\n                new GenericRequestHeaderInterceptor(headers)));\n        }\n\n        return template;\n    }\n\n    private void addAuthorizationToken(ConfigClientProperties configClientProperties,\n                                       HttpHeaders httpHeaders, String username, String password) {","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SentinelRuleLocator.java#L221-L257","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Search the config (including environment variables and bootstrap.yml) for negative timeout values and fix them.","If the value is computed, clamp it: Math.max(0, configuredTimeout)."],"exampleFix":"# before\nspring.cloud.config.request-read-timeout: -1\n\n# after\nspring.cloud.config.request-read-timeout: 60000","handlingStrategy":"validation","validationCode":"int readTimeout = Math.max(0, configuredReadTimeoutMs); // clamp before it reaches the client\nSystem.setProperty(\"spring.cloud.config.request-read-timeout\", String.valueOf(readTimeout));","typeGuard":null,"tryCatchPattern":"try {\n    locator.locate(environment);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Read Timeout\")) {\n        throw new IllegalStateException(\"request-read-timeout must be >= 0 ms; fix config\", e);\n    }\n    throw e;\n}","preventionTips":["Never use -1 for HTTP timeouts in Spring Cloud Config; use 0 for infinite or a positive ms value.","Validate numeric config values at startup with clamping or explicit checks."],"tags":["sentinel","spring-cloud-config","timeout","configuration","java"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}