slfan1989 opened a new pull request, #1357:
URL: https://github.com/apache/ratis/pull/1357

   ## What changes were proposed in this pull request?
   
   This PR fixes a memory leak in `NettyClientReplies` caused by creating empty 
`ReplyMap` entries for unknown/stale replies.
   
   **Problem:**
   When `NettyClientStreamRpc.channelRead()` receives a reply without a 
corresponding request (e.g., after timeout or cleanup), the original code would:
   1. Call `replies.getReplyMap(clientInvocationId)` which uses 
`computeIfAbsent`
   2. Create a new empty `ReplyMap` if the invocation ID doesn't exist
   3. Find no matching request and return early
   4. Leave the empty map in memory permanently
   
   **Solution:**
   - Added `NettyClientReplies.getReplyMapIfPresent()` that only retrieves 
existing ReplyMaps without creating new ones
   - Changed `channelRead()` to use `getReplyMapIfPresent()` instead of 
`getReplyMap()`
   - When `null` is returned, log an error and return early without creating 
leaked objects
   
   The `getReplyMap()` method is still used in `streamAsync()` where creating 
new ReplyMaps is the intended behavior for new requests.
   
   
   ## What is the link to the Apache JIRA
   
   JIRA: RATIS-2416. Fix memory leak in NettyClientReplies for stale replies.
   
   Please replace this section with the link to the Apache JIRA)
   
   ## How was this patch tested?
   
   Exists Junit Test.


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

Reply via email to