Aias00 opened a new issue, #6445:
URL: https://github.com/apache/shenyu/issues/6445

   ### Current Behavior
   
   `MemorySafeLinkedBlockingQueue.put(e)` enqueues the element when memory is 
available, but then calls the rejector unconditionally.
   
   Evidence:
   
   
`shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueue.java:88-94`
   
   ```java
   @Override
   public void put(final E e) throws InterruptedException {
       if (hasRemainedMemory()) {
           super.put(e);
       }
       rejector.reject(e, this);
   }
   ```
   
   This differs from `offer(...)`, which only invokes the rejector when 
`hasRemainedMemory()` is false.
   
   With a non-default rejector, `put(e)` can both enqueue the element and then 
reject/mutate again:
   
   - `AbortPolicy` throws after the item was already queued.
   - `DiscardOldestPolicy` can remove an older item after the new item has 
already been inserted.
   
   That violates the expected `BlockingQueue.put` contract and can produce 
false failures or unexpected task loss.
   
   ### Expected Behavior
   
   `put(e)` should only call the rejector when the memory guard rejects the 
insertion. If memory is available and `super.put(e)` succeeds, the method 
should return normally.
   
   ### Steps To Reproduce
   
   1. Create a `MemorySafeLinkedBlockingQueue` with enough available memory.
   2. Set a non-default rejector, for example `AbortPolicy`.
   3. Call `put(e)`.
   4. The element is inserted by `super.put(e)`, then `rejector.reject(e, 
this)` still executes.
   
   ### Suggested Fix
   
   Return immediately after successful `super.put(e)`, or invert the condition:
   
   ```java
   if (!hasRemainedMemory()) {
       rejector.reject(e, this);
       return;
   }
   super.put(e);
   ```
   


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