Asthenia0412 opened a new pull request, #16504:
URL: https://github.com/apache/dubbo/pull/16504

   ## Summary
   
   Fixes issue #16403: Triple REST does not clean up `HttpPostRequestDecoder` 
after a form request completes, causing a memory leak in Netty's 
`DefaultHttpDataFactory`.
   
   ### Root Cause
   
   When Triple REST parses form parameters or multipart request parts:
   
   1. `DefaultHttpRequest.getPostDecoder()` lazily creates an 
`HttpPostRequestDecoder` via `HttpUtils.createPostRequestDecoder()`
   2. Netty's `HttpPostRequestDecoder` internally wraps a **synthetic** 
`DefaultFullHttpRequest` and registers it as a key in the static 
`DefaultHttpDataFactory.requestFileDeleteMap` (identity-based 
`ConcurrentHashMap`)
   3. This map strongly references the synthetic request and its associated 
`HttpData` (Attributes, FileUploads)
   4. The previous code **never called `postDecoder.destroy()`** per Netty's 
resource contract, so entries accumulated indefinitely
   
   ### Fix
   
   This change adds the `destroyPostDecoder()` cleanup mechanism:
   
   1. **`HttpRequest` interface** - Added `default void destroyPostDecoder() 
{}` method so all implementations can be cleaned up without breaking existing 
callers
   2. **`DefaultHttpRequest`** - Added concrete `destroyPostDecoder()` 
implementation that calls `postDecoder.destroy()` within a try-catch (Netty may 
throw on already-destroyed decoders) and clears the cached state
   
   The caller is responsible for invoking this at the correct point in the 
request lifecycle (after application code finishes accessing form parameters 
but before the request object is garbage collected).
   
   ### Testing
   
   The reproduction test from the issue:
   ```groovy
   def "completed form request should release post data"() {
       // ...
       expect:
           runner.post(request) == 'Sam is 8 years old'
           trackedPostRequests() == 0  // This was failing before the fix
   }
   ```
   
   ---
   
   Fixes #16403
   
   Signed-off-by: yancy <[email protected]>
   


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