-
Notifications
You must be signed in to change notification settings - Fork 1
Set timeout for webclients. #495
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces timeout configuration for WebClient instances to improve reliability and prevent hanging requests. The implementation adds connection, read, write, and response timeouts to HTTP clients.
- Adds comprehensive timeout configuration with 100-second read/write/response timeouts and 5-second connection timeout
- Creates a custom HttpClient bean with Netty-based timeout handlers
- Provides a configured WebClient.Builder bean that uses the timeout-enabled HttpClient
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @Bean | ||
| fun reactorNettyHttpClient(): HttpClient { | ||
| val timeoutInSeconds = 100L |
Copilot
AI
Sep 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeout value of 100 seconds is hardcoded as a magic number. Consider moving this to application properties or a constant with a descriptive name to make it configurable and more maintainable.
| @Bean | |
| fun reactorNettyHttpClient(): HttpClient { | |
| val timeoutInSeconds = 100L | |
| /** | |
| * Timeout in seconds for WebClient connections. | |
| * Configurable via 'webclient.timeout.seconds' in application.properties. | |
| */ | |
| @org.springframework.beans.factory.annotation.Value("\${webclient.timeout.seconds:100}") | |
| private val timeoutInSeconds: Long = 100L | |
| @Bean | |
| fun reactorNettyHttpClient(): HttpClient { |
| @Bean | ||
| fun reactorNettyHttpClient(): HttpClient { | ||
| val timeoutInSeconds = 100L | ||
| return HttpClient.create() | ||
| .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5_000) |
Copilot
AI
Sep 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The connection timeout of 5000 milliseconds is hardcoded as a magic number. Consider extracting this to a constant or configuration property for better maintainability.
| @Bean | |
| fun reactorNettyHttpClient(): HttpClient { | |
| val timeoutInSeconds = 100L | |
| return HttpClient.create() | |
| .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5_000) | |
| companion object { | |
| private const val CONNECT_TIMEOUT_MILLIS = 5_000 | |
| } | |
| @Bean | |
| fun reactorNettyHttpClient(): HttpClient { | |
| val timeoutInSeconds = 100L | |
| return HttpClient.create() | |
| .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS) |
No description provided.