Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MudSnackbar: Snapshot enumeration to avoid concurrent collection access#13187

Merged
danielchalmers merged 2 commits into
devfrom
copilot/improve-snackbars-thread-safety
May 11, 2026
Merged

MudSnackbar: Snapshot enumeration to avoid concurrent collection access#13187
danielchalmers merged 2 commits into
devfrom
copilot/improve-snackbars-thread-safety

Conversation

Copilot AI commented May 11, 2026

Copy link
Copy Markdown
Contributor

ISnackbar.ShownSnackbars could expose a deferred enumeration over the mutable backing list after the lock had been released. This change narrows the fix to that concurrency edge by returning a stable snapshot and adding coverage for enumeration after subsequent mutations.

  • Snackbar service

    • Return a materialized snapshot from ShownSnackbars instead of a deferred Take(...) over the live list.
    • Preserve existing MaxDisplayedSnackbars behavior and ordering while making callers safe from post-read mutations.
  • Regression coverage

    • Add a service-level test that captures ShownSnackbars, mutates the service state, and verifies the original enumeration remains unchanged.
public IEnumerable<Snackbar> ShownSnackbars
{
    get
    {
        _snackBarLock.EnterReadLock();
        try
        {
            return _snackBarList.Take(Configuration.MaxDisplayedSnackbars).ToArray();
        }
        finally
        {
            _snackBarLock.ExitReadLock();
        }
    }
}

@danielchalmers danielchalmers marked this pull request as ready for review May 11, 2026 18:02
@mudbot mudbot Bot added the bug Unexpected behavior or functionality not working as intended label May 11, 2026
@mudbot mudbot Bot changed the title Snapshot snackbar enumeration to avoid concurrent collection access MudSnackbar: Snapshot enumeration to avoid concurrent collection access May 11, 2026
@danielchalmers danielchalmers merged commit 5834677 into dev May 11, 2026
11 checks passed
@danielchalmers danielchalmers deleted the copilot/improve-snackbars-thread-safety branch May 11, 2026 18:06
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants