YvCeung commented on code in PR #7684:
URL: https://github.com/apache/incubator-seata/pull/7684#discussion_r2435295143


##########
common/src/main/java/org/apache/seata/common/http/Http1HttpExecutor.java:
##########
@@ -54,6 +58,25 @@ public class HttpClientUtil {
 
     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
+    public static volatile Http1HttpExecutor instance;
+
+    /**
+     * Gets instance.
+     *
+     * @return the instance
+     */
+    public static Http1HttpExecutor getInstance() {
+
+        if (instance == null) {
+            synchronized (Http1HttpExecutor.class) {
+                if (instance == null) {
+                    instance = new Http1HttpExecutor();
+                }
+            }
+        }
+        return instance;
+    }

Review Comment:
   > Why does this instance need to be a singleton?
   
   当我们希望通过 HTTP/2 发起请求时,不仅需要检测客户端是否支持,还必须确认 Seata Server 端 是否具备 HTTP/2 能力。
   
   如果直接使用抽象类提供的通用 API 发起调用,可能会出现这样的问题:客户端最终使用了 HTTP/2 
实现类,但服务端并不支持,从而导致不可预期的异常。原因在于当前的依赖检测逻辑中,尚未包含对 Server 端协议版本 的校验。
   
   因此,为了保证在某些场景下能够安全运行,我暂时为每个实现类单独保留了 getInstance() 方法,便于手动选择合适的实现。
   
   待后续在依赖探测中集成 “Server 端 HTTP/2 支持判断” 能力后,这些单例获取方法就可以被移除。届时,所有 HTTP 请求都可统一通过 
`HttpExecutorFactory.getInstance()` 进行调用。
   
   This logic serves as a transitional solution.
   
   When we intend to initiate requests over HTTP/2, we must verify not only the 
client’s capability but also whether the Seata Server supports HTTP/2.
   
   If we directly invoke the generic API provided by the abstract class, it’s 
possible that the actual implementation used on the client side is based on 
HTTP/2 while the server does not support it. This could lead to unpredictable 
exceptions, since the current dependency check mechanism does not include 
validation for the server-side protocol version.
   
   To ensure stability under such conditions, each implementation class 
temporarily provides its own getInstance() method, allowing manual selection of 
the proper executor.
   
   Once the capability detection logic is enhanced to determine whether the 
server supports HTTP/2, these per-class singleton access methods can be safely 
removed. At that point, all HTTP requests can be uniformly initiated via 
`HttpExecutorFactory.getInstance()`.



-- 
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