Skip to content

System.Threading.RateLimiting.ChainedRateLimiter #125560

@lobster2012-user

Description

@lobster2012-user

Description

Hello!
I found a few bugs in the class System.Threading.RateLimiting.ChainedRateLimiter

  1. Implemenration of IdleDuration

If at least one IdleDuration object is non-null, a non-null value will be returned always. This will clear the entire chain in DefaultPartitionedRateLimiter.Heartbeat. Even if there are active limiters with nullable idleDuration.

public override TimeSpan? IdleDuration
        {
            get
            {
                ThrowIfDisposed();

                TimeSpan? lowestIdleDuration = null;

                foreach (RateLimiter limiter in _limiters)
                {
                    if (limiter.IdleDuration is { } idleDuration)
                    {
                        if (lowestIdleDuration is null || idleDuration < lowestIdleDuration)
                        {
                            lowestIdleDuration = idleDuration;
                        }
                    }
                }

                return lowestIdleDuration;
            }
        }
  1. ChainedRateLimiter not implements ReplenishingRateLimiter
    Because of this, the TryReplenish method will not be called for the chain of child objects.
    See DefaultPartitionedRateLimiter.Heartbeat

Reproduction Steps

I tried to use this class and caught the described bugs.

Expected behavior

Code without bugs

Actual behavior

Code without bugs

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions