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

   ## Description
   
   MemoryLimitedLinkedBlockingQueue can expose queue contents and byte 
reservations that disagree. Its collection constructor enqueues seed elements 
before initializing an empty MemoryLimiter; inherited bulk/iterator removal 
methods can remove normal elements without releasing their reservations.
   
   These are two entry points to the same queue-accounting invariant and are 
tracked together.
   
   ## Reproduction
   
   Current-source standalone Java harness with Instrumentation returning a 
deterministic 10-byte object size:
   
   ```text
   drainTo: drained=2, queueSize=0, reserved=20, nextOffer=false
   iterator.remove: queueSize=0, reserved=10
   collection ctor: queueSize=1, reserved=0
   collection ctor take: removedItemButBlocked=true, remainingQueueSize=0
   ```
   
   For drainTo, enqueue two 10-byte entries into a 21-byte budget, drain them, 
then offer another entry. The queue is empty, but the 20-byte charge remains 
and admission fails.
   
   For the collection constructor, seed one entry and call take(). The 
superclass removes it, but MemoryLimiter.releaseInterruptibly waits for a 
nonexistent reservation, so take never returns until another action changes 
accounting or the thread is interrupted.
   
   The harness waits for the exact MemoryLimiter condition stack, includes 
cleanup, and avoids sleep-based scheduling assumptions. Independent 
verification reproduced both cases.
   
   ## Location
   
   - 
[MemoryLimitedLinkedBlockingQueue.java:47](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitedLinkedBlockingQueue.java#L47):
 collection seed is not charged.
   - 
[MemoryLimitedLinkedBlockingQueue.java:103](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitedLinkedBlockingQueue.java#L103):
 take removes first, then waits for accounting release.
   - 
[MemoryLimitedLinkedBlockingQueue.java:139](https://github.com/apache/shenyu/blob/a89b6a2338c24e978428b731e8f1edce86022418/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitedLinkedBlockingQueue.java#L139):
 implemented removal hooks do not cover inherited bulk/iterator APIs.
   
   ## Impact
   
   Severity: Medium. Confidence: high. Queue operations can block despite 
initially available data or reject work despite an empty queue. The subclass is 
also the base of MemoryLimitedTaskQueue, used by the gateway shared-pool 
configuration; standard executor cancellation/purge/drain operations must not 
leak admission budget.
   
   ## Suggested Fix And Tests
   
   Initialize accounting consistently for seeds and maintain it for every 
successful public removal path. Test collection take/poll, over-budget seeds, 
drainTo overloads, iterator removal, removeIf/removeAll/retainAll, normal 
dequeue and clear. Preserve cancellation/interrupt semantics.
   
   ## Validation And Deduplication
   
   Reviewed apache/shenyu master a89b6a2338c24e978428b731e8f1edce86022418. 
Actual current classes compiled with javac; leader and isolated reviewer 
assertions reproduced the failure. Instrumentation size is mocked, not the 
queue/limiter logic.
   
   #3318 concerned reading a stale sum after a condition wake; #6815 concerned 
timing of a unit test. Neither covers seeded/bulk mutation accounting. No 
matching open/closed issue or pending PR was found.
   
   
   ## Reviewed Revision And Validation
   
   Apache ShenYu 2.7.2-SNAPSHOT, master at 
a89b6a2338c24e978428b731e8f1edce86022418. Severity: medium. Confidence: high.
   
   Leader and isolated verifier ran deterministic queue 
constructor/drain/iterator assertions.
   
   No implementation fix or full deployed end-to-end validation was performed 
by this review. Source-flow and runtime evidence are distinguished above.
   


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