Skip to content

ThrottleDispatcher: Fix not throttling fast-completing actions#12636

Merged
ScarletKuro merged 1 commit intoMudBlazor:devfrom
ScarletKuro:dev
Feb 8, 2026
Merged

ThrottleDispatcher: Fix not throttling fast-completing actions#12636
ScarletKuro merged 1 commit intoMudBlazor:devfrom
ScarletKuro:dev

Conversation

@ScarletKuro
Copy link
Member

Regression introduced in #12296 (1e9837ae). The refactor replaced the original two-part guard:

// OLD — checked busy OR time
if (_lastTask is not null && (_busy || ShouldWait()))
    return _lastTask;

with a single condition that only checks the interval when the task is still running:

// NEW — only checks time when task is incomplete
if (_currentTask is not null &&
    !_currentTask.IsCompleted &&
    timeSinceLastExecution < _interval)
    return _currentTask;

Problem

When the action completes synchronously, IsCompleted is already true on the next call.
The completed task gets cleared and a new execution starts unconditionally, the time check is never reached.

Fix

Check the interval regardless of task completion state. Faulted tasks still allow immediate retry:

if (timeSinceLastExecution < _interval &&
    _currentTask is not null &&
    !_currentTask.IsFaulted)
{
    return _currentTask.IsCompleted
        ? Task.CompletedTask
        : _currentTask;
}

Why tests didn’t catch it

  • slow async actions (Task.Delay) that keep the task running, or
  • real delays between calls that exceed the interval.

No test covered the real MudColorPicker scenario: a synchronous action called rapidly within the interval.

Checklist:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests

@mudbot mudbot bot added bug Unexpected behavior or functionality not working as intended regression Previously worked and now doesn't labels Feb 8, 2026
@ScarletKuro ScarletKuro merged commit f212a23 into MudBlazor:dev Feb 8, 2026
11 checks passed
@ScarletKuro ScarletKuro removed the bug Unexpected behavior or functionality not working as intended label Feb 8, 2026
@danielchalmers danielchalmers added the bug Unexpected behavior or functionality not working as intended label Feb 11, 2026
This was referenced Feb 20, 2026
This was referenced Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended regression Previously worked and now doesn't

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants