Skip to content

Provide a property that configures webclient/webtestclients default timeout globally #34711

Duplicate of#43079
@nightswimmings

Description

@nightswimmings

I think, WebClient/WebTestClient(Builder) should be able to configure defaults through properties, especially timeout and especially for WebTestClient, since its a setup most people would tune in order to being able to debug for long time and not get a connection exception.

Kind of @AutoConfigureWebTestClient(timeout = "10000"), but through properties on a global scope.

My apologies if such a setup exists, I could not find it in issues nor spring-boot-properties docs

Activity

changed the title [-]Provide a property that configures webclient/webtestclients timeout globally[/-] [+]Provide a property that configures webclient/webtestclients default timeout globally[/+] on Mar 22, 2023
philwebb

philwebb commented on Mar 22, 2023

@philwebb
Member

See also #31496

philwebb

philwebb commented on Mar 22, 2023

@philwebb
Member

We're not totally sure that a property is the best solution, but it would be really nice if we could offer a better way to programmatically change the timeout for an individual WebClient.builder(). We'll need to do some more design work for this one and possibly request changes in spring-framework.

added and removed
for: team-meetingAn issue we'd like to discuss as a team to make progress
on Mar 22, 2023
added this to the General Backlog milestone on Mar 22, 2023
nightswimmings

nightswimmings commented on Mar 23, 2023

@nightswimmings
Author

To be honest Phil, I think global would be convenient for WebClient , at least during test, since when debugging (at least webclient's non-reactive) communications, it's very annoying to get java.lang.IllegalStateException: Timeout on blocking read for X NANOSECONDS, every then and now. I'm not exactly sure of the internal mechanics of flux timings (maybe it's my fault on conceptual design), but I assume it's a matter of the lazy/future-evaluations chain because I never suffer them with servlet arch. But just my 2c as a heavy user

nightswimmings

nightswimmings commented on Apr 8, 2023

@nightswimmings
Author

If this goes on, there is another property that would benefit from this, logging: https://stackoverflow.com/questions/46154994/how-to-log-spring-5-webclient-call

mvitz

mvitz commented on Jun 19, 2024

@mvitz
Contributor

@philwebb any news about this one?

I was, internally, asked how to configure timeouts for the new RestClient.

My current solution is a RestClientCustomizer that sets a custom ClientHttpRequestFactory.
To rely on the default decision tree of Spring Boot which client library to use, I “stole” the ClientHttpRequestFactories.get(...) approach of the autoconfiguration.

Especially, reusing this logic was only possible because I looked into the source code of the autoconfiguration.
If not adding properties for configuring these timeouts, it would at least be a good idea to enhance the Spring Documentation about RestClient and include a hint to ClientHttpRequestFactories there.

philwebb

philwebb commented on Jun 20, 2024

@philwebb
Member

@mvitz There's no update on this one yet I'm afraid

mvitz

mvitz commented on Jun 21, 2024

@mvitz
Contributor

@philwebb Thanks for your quick reply.
Anything I can do to help?

I understand that this case is special because configuring a builder via properties is not that common but on the other hand being able to easily configure things like timeouts would be useful, too.

I was thinking if something like spring.client.rest.default.connection.read-timeout would be an option.
In theory the matching @ConfigurationProperties-Class could be even reusable for configuring application specific instances.

Let me know if theres anything I can do to help/support.

removed
for: team-meetingAn issue we'd like to discuss as a team to make progress
on Jul 11, 2024
a1shadows

a1shadows commented on Aug 9, 2024

@a1shadows

Is there anything I can do to help? This is a feature that would be super useful for us.
SO question regarding the same: https://stackoverflow.com/questions/78675295/are-there-any-spring-properties-to-set-defaults-for-spring-webclient

mvitz

mvitz commented on May 26, 2025

@mvitz
Contributor

@philwebb I'm not the author of this ticket, but I think the last changes (documented at https://docs.spring.io/spring-boot/reference/io/rest-client.html#io.rest-client.webclient.configuration) seems to fix at least the majority described here.

philwebb

philwebb commented on May 27, 2025

@philwebb
Member

Thanks @mvitz, I think you're right and this has now been fixed.

removed this from the General Backlog milestone on May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @philwebb@mvitz@nightswimmings@spring-projects-issues@a1shadows

        Issue actions

          Provide a property that configures webclient/webtestclients default timeout globally · Issue #34711 · spring-projects/spring-boot