Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read-Timeout not applied with Apache Http Components and no-SSL #861

Closed
p120ph37 opened this issue Mar 19, 2024 · 3 comments
Closed

Read-Timeout not applied with Apache Http Components and no-SSL #861

p120ph37 opened this issue Mar 19, 2024 · 3 comments
Labels
type: bug A general bug
Milestone

Comments

@p120ph37
Copy link

p120ph37 commented Mar 19, 2024

When using Apache Http Components with an http (non-SSL) Vault URI, the read-timeout option is not applied to the HttpClientBuilder. This results in the Apache-default of 3-minutes always being used, regardless of the settings provided via Spring Boot.

I've created a trivial example project to demonstrate the issue here: https://github.com/p120ph37/spring-vault-test

I believe the fix would be to add .setResponseTimeout(Timeout.ofMilliseconds(options.getReadTimeout().toMillis())) here:

RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(options.getConnectionTimeout().toMillis()))
.setAuthenticationEnabled(true) //
.setRedirectsEnabled(true)
.build();

I have prototyped this fix in the FixedClientFactoryWrapper in my test suite -- test that fix by uncommenting this line: https://github.com/p120ph37/spring-vault-test/blob/0ffcea4bc2d7401721f29b419c9596c91827023b/src/test/java/spring/vault/test/TimeoutTests.java#L43

@p120ph37
Copy link
Author

As a temporary workaround for Spring Boot applications that need to support timeouts on HTTP Vault requests, adding this bean to your application will force the use of the JDK request factory rather than the Apache one:

        // This is a workaround for https://github.com/spring-projects/spring-vault/issues/861
        @Bean
        @Order(Ordered.HIGHEST_PRECEDENCE)
        org.springframework.vault.client.RestTemplateCustomizer restTemplateCustomizer(VaultProperties vp) {
            return rt -> {
                if(vp.getSsl().getKeyStore() == null && vp.getSsl().getTrustStore() == null) {
                    SimpleClientHttpRequestFactory rf = new SimpleClientHttpRequestFactory();
                    rf.setConnectTimeout(vp.getConnectionTimeout());
                    rf.setReadTimeout(vp.getReadTimeout());
                    rt.setRequestFactory(rf);
                }
            };
        }

@mp911de mp911de added the type: bug A general bug label Apr 2, 2024
@mp911de
Copy link
Member

mp911de commented Apr 2, 2024

Thanks for the report. We should fix that issue in HttpComponents.getHttpClientBuilder(…). Since you already had a look into the issue, care to submit a pull request?

@Entea
Copy link
Contributor

Entea commented May 15, 2024

I've stumbled upon the same problem and found this issue. I've submitted a PR

mp911de added a commit that referenced this issue May 16, 2024
Configure ResponseTimeout for a Request, move off deprecated API by always configuring a PoolingHttpClientConnectionManager.

See gh-861
Original pull request: gh-866
mp911de pushed a commit that referenced this issue May 16, 2024
mp911de added a commit that referenced this issue May 16, 2024
Configure ResponseTimeout for a Request, move off deprecated API by always configuring a PoolingHttpClientConnectionManager.

See gh-861
Original pull request: gh-866
@mp911de mp911de added this to the 3.1.2 milestone May 16, 2024
natedanner pushed a commit to natedanner/spring-projects__spring-vault that referenced this issue May 20, 2024
natedanner pushed a commit to natedanner/spring-projects__spring-vault that referenced this issue May 20, 2024
Configure ResponseTimeout for a Request, move off deprecated API by always configuring a PoolingHttpClientConnectionManager.

See spring-projectsgh-861
Original pull request: spring-projectsgh-866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants