Skip to content

QueueProcessingOrder.NewestFirst WaitAsync should drop the oldest item when the queue is full #62817

Description

@Tratcher

Description

QueueProcessingOrder.NewestFirst is used for a stack pattern (FILO), so the newest entry in line always gets processed next. However, when the queue fills up it starts refusing to add new entries, keeping older entries in the queue.

Instead, it should add the new entry to the front and drop the oldest entry from the back.

Reproduction Steps

        var limiter = new System.Threading.RateLimiting.ConcurrencyLimiter(
            new System.Threading.RateLimiting.ConcurrencyLimiterOptions(
                permitLimit: 1, queueProcessingOrder: QueueProcessingOrder.NewestFirst, queueLimit: 2));

        var lease1 = limiter.Acquire(); // Succeeds, exhausts permitLimit.
        var lease2Task = limiter.WaitAsync(); // Incomplete, queued
        var lease3Task = limiter.WaitAsync(); // Incomplete, queued, exhausts queueLimit.

        var lease4Task = limiter.WaitAsync();
        // Expected: Incomplete, lease2Task completes without acquiring.
        // Actual: Completes immediately without acquiring. lease2Task remains queued.

Expected behavior

WaitAsync should queue a new item and drop the oldest item when the queue is full

Actual behavior

WaitAsync does not queue a new item and maintains the oldest item when the queue is full

Regression?

No response

Known Workarounds

No response

Configuration

.NET 7

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Dec 14, 2021
  2. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 4, 2022
  3. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 19, 2022
  4. added this to the 7.0.0 milestone on Jan 19, 2022
  5. added and removed
    untriagedNew issue has not been triaged by the area owner
    on Jan 19, 2022
  6. ghost locked as resolved and limited conversation to collaborators on Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions