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

WebClient Timeouts and SSL Configuration are incompatible #36263

Open
jjoslet opened this issue Jul 6, 2023 · 7 comments
Open

WebClient Timeouts and SSL Configuration are incompatible #36263

jjoslet opened this issue Jul 6, 2023 · 7 comments
Labels
theme: http-client-config Issues related to configuration of HTTP clients theme: ssl Issues related to ssl support type: bug A general bug
Milestone

Comments

@jjoslet
Copy link

jjoslet commented Jul 6, 2023

I followed the Spring Boot and Spring Framework documentations to configure a WebClient with Spring Boot 3.1.1.

I have

These configurations are incompatible since they both set the ClientHttpConnector on the WebClient.Builder; the second configuration overrides the first one.

Here is a small application to reproduce:

@SpringBootApplication(proxyBeanMethods = false)
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	
	@Bean
	WebClient webClient(WebClient.Builder builder, WebClientSsl ssl) {
		HttpClient httpClient = HttpClient.create()
			.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1);
	
		return builder
			.clientConnector(new ReactorClientHttpConnector(httpClient)) // TIMEOUT
			.apply(ssl.fromBundle("demobundle")) // SSL
			.build();
	}
	
	@Bean
	ApplicationRunner runner(WebClient webClient) {
		return new ApplicationRunner() {
			@Override
			public void run(ApplicationArguments args) throws Exception {
				webClient.head()
					.uri("https://www.google.com")
					.exchangeToMono(r -> Mono.just(r.statusCode()))
					.doOnSuccess(System.out::println)
					.block();
			}
		};
	}
}

with the following properties:

spring.ssl.bundle.pem.demobundle.key.password=password
spring.ssl.bundle.pem.demobundle.key.alias=alias

In that situation, a timeout does not occur but if I switch // TIMEOUT with // SSL lines, a timeout will occur but SSL is no more configured.

I didn't find a proper way to configure this without recreating the full SSL configuration in my application.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 6, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 6, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Jul 6, 2023
@ramanpopli
Copy link

Is someone working on it . I would like to contribute on this , but I would request if I can get little more overview on this .

@wilkinsona
Copy link
Member

Thanks for the offer, @ramanpopli. If you’d like to work on an issue where we provide some guidance, please watch for one labelled as ideal for contribution or, if you haven’t contributed before, first-timers only.

@mhalbritter
Copy link
Contributor

mhalbritter commented Sep 18, 2023

If we would make the org.springframework.boot.autoconfigure.web.reactive.function.client.ReactorClientHttpConnectorFactory.SslConfigurer public API and add a static method to it:

public static HttpClient applyBundle(SslBundle sslBundle, HttpClient httpClient) {
  return new SslConfigurer(sslBundle).configure(httpClient);
}

then we could workaround that problem with:

HttpClient httpClient = HttpClient.create().option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1);
httpClient = SslConfigurer.applyBundle(sslBundles.getBundle("demobundle"), httpClient); // SSL
WebClient webClient = builder
  .clientConnector(new ReactorClientHttpConnector(httpClient)) // TIMEOUT
  .build();

(SslBundles can be injected, too)

@eloo-abi

This comment was marked as outdated.

@mhalbritter

This comment was marked as outdated.

@eloo-abi
Copy link

eloo-abi commented Nov 6, 2023

okay..
we have found a workaround/solution maybe
maybe this can be verified if this would be a proper way to configure it?

    @Bean
    ReactorNettyHttpClientMapper reactorNettyHttpClientMapper() {
        return httpClient -> httpClient
            .responseTimeout(webClientProperties.http.responseTimeoutInMs)
            .option(CONNECT_TIMEOUT_MILLIS, (int) webClientProperties.http.connectTimeoutInMs.toMillis());
    }

but i'm not sure if this fits all purposes as this is "globally" then and will also affect nonssl webclients as well

@scottfrederick scottfrederick added the theme: ssl Issues related to ssl support label Nov 16, 2023
@scottfrederick scottfrederick added the theme: http-client-config Issues related to configuration of HTTP clients label Jan 9, 2024
@kzander91
Copy link
Contributor

okay.. we have found a workaround/solution maybe maybe this can be verified if this would be a proper way to configure it?

    @Bean
    ReactorNettyHttpClientMapper reactorNettyHttpClientMapper() {
        return httpClient -> httpClient
            .responseTimeout(webClientProperties.http.responseTimeoutInMs)
            .option(CONNECT_TIMEOUT_MILLIS, (int) webClientProperties.http.connectTimeoutInMs.toMillis());
    }

but i'm not sure if this fits all purposes as this is "globally" then and will also affect nonssl webclients as well

You're right in that this would be global, affecting all auto-configured WebClient.Builders. I'm in a similar situation to OP in that I have a specific WebClient that I want to apply WebClientSsl to and configure it to use a proxy server.

In my application I have several other services I need to call and the corresponding WebClient instances need to be configured without proxy, so a global configuration via ReactorNettyHttpClientMapper doesn't work for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: http-client-config Issues related to configuration of HTTP clients theme: ssl Issues related to ssl support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

9 participants