Copilot commented on code in PR #7957:
URL: https://github.com/apache/incubator-seata/pull/7957#discussion_r2724781040


##########
namingserver/src/main/java/org/apache/seata/namingserver/config/WebConfig.java:
##########
@@ -38,19 +39,17 @@ public class WebConfig {
 
     @Bean
     public RestTemplate restTemplate() {
-        // Create a connection manager with custom settings
-        PoolingHttpClientConnectionManager connectionManager = new 
PoolingHttpClientConnectionManager();
-        connectionManager.setMaxTotal(DEFAULT_CONNECTION_MAX_TOTAL); // 
Maximum total connections
-        
connectionManager.setDefaultMaxPerRoute(DEFAULT_CONNECTION_MAX_PER_ROUTE); // 
Maximum connections per route
-        // Create an HttpClient with the connection manager
-        CloseableHttpClient httpClient =
-                
HttpClients.custom().setConnectionManager(connectionManager).build();
-        // Create a request factory with the HttpClient
-        HttpComponentsClientHttpRequestFactory requestFactory = new 
HttpComponentsClientHttpRequestFactory(httpClient);
-        requestFactory.setConnectTimeout(DEFAULT_REQUEST_TIMEOUT); // 
Connection timeout in milliseconds
-        requestFactory.setReadTimeout(DEFAULT_REQUEST_TIMEOUT); // Read 
timeout in milliseconds
-        // Create and return a RestTemplate with the custom request factory
-        return new RestTemplate(requestFactory);
+        Dispatcher dispatcher = new Dispatcher();
+        dispatcher.setMaxRequests(DEFAULT_CONNECTION_MAX_TOTAL);
+        dispatcher.setMaxRequestsPerHost(DEFAULT_CONNECTION_MAX_PER_ROUTE);
+
+        OkHttpClient client = new OkHttpClient.Builder()
+                .dispatcher(dispatcher)
+                .connectTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS)
+                .readTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS)

Review Comment:
   Consider adding writeTimeout configuration to match the pattern used in 
HttpClientUtil 
(common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java:205,215).
 While the original HttpClient configuration didn't explicitly set a write 
timeout, OkHttp best practices recommend setting all three timeouts (connect, 
read, write) to prevent indefinite hangs during request transmission.
   ```suggestion
                   .readTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS)
                   .writeTimeout(DEFAULT_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to