Copilot commented on code in PR #16504:
URL: https://github.com/apache/dubbo/pull/16504#discussion_r4268778355


##########
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpRequest.java:
##########
@@ -676,6 +676,28 @@ public void setInputStream(InputStream is) {
         }
     }
 
+    /**
+     * Destroys the cached HttpPostRequestDecoder if it was created for parsing
+     * form data or multipart requests. This releases the synthetic request and
+     * HttpData entries held by the static {@code DefaultHttpDataFactory},
+     * preventing memory leaks after form request processing completes.
+     *
+     * <p>Should be called once the request has been fully processed and no
+     * further access to form parameters or multipart parts is required.
+     */

Review Comment:
   Since `destroyPostDecoder()` is now part of the `HttpRequest` interface, 
this implementation should be annotated with `@Override` to let the compiler 
enforce signature correctness and make the contract clearer.



##########
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpRequest.java:
##########
@@ -24,6 +24,8 @@
 import java.util.Locale;
 import java.util.Map;
 
+import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
+

Review Comment:
   This import appears to be used only for Javadoc linking, which typically 
does not count as usage for style tools (e.g., Checkstyle unused-import rules) 
and may fail the build. Consider removing the import and updating the Javadoc 
to reference the type via its fully-qualified name (e.g., {@link 
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder#destroy()}) to 
avoid unused-import violations.



##########
dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/DefaultHttpRequest.java:
##########
@@ -676,6 +676,28 @@ public void setInputStream(InputStream is) {
         }
     }
 
+    /**
+     * Destroys the cached HttpPostRequestDecoder if it was created for parsing
+     * form data or multipart requests. This releases the synthetic request and
+     * HttpData entries held by the static {@code DefaultHttpDataFactory},
+     * preventing memory leaks after form request processing completes.
+     *
+     * <p>Should be called once the request has been fully processed and no
+     * further access to form parameters or multipart parts is required.
+     */
+    public void destroyPostDecoder() {
+        if (postDecoder != null) {
+            try {
+                postDecoder.destroy();
+            } catch (Exception ignored) {
+                // Netty may throw if the decoder is already destroyed
+            } finally {

Review Comment:
   Catching and silently ignoring all `Exception`s can hide real cleanup 
failures (e.g., unexpected runtime issues), making memory/resource leaks harder 
to diagnose in production. Prefer catching the specific exception(s) Netty 
throws for already-destroyed decoders, or at least log at debug/trace level 
when an unexpected exception occurs while still ensuring the `finally` cleanup 
runs.



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