Skip to content

Prevent Race Condition Allowing Simultaneous Calling of Navigation.PushModalAsync() / Shell.GotoAsync() in PopupExtensions - #3234

Merged
TheCodeTraveler merged 8 commits into
mainfrom
Fix-Issue-3192
Jun 6, 2026
Merged

Prevent Race Condition Allowing Simultaneous Calling of Navigation.PushModalAsync() / Shell.GotoAsync() in PopupExtensions#3234
TheCodeTraveler merged 8 commits into
mainfrom
Fix-Issue-3192

Conversation

@TheCodeTraveler

@TheCodeTraveler TheCodeTraveler commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Description of Change

This PR fixes the race condition where PopupExtensions could call Navigation.PushModalAsync() / Shell.GotoAsync() to display a Popup while a previously-called Navigation.PushModalAsync() / Shell.GotoAsync() could actively be running.

To avoid this race condition, I added SemaphoreSlim showPopupSemaphoreSlim = new(1, 1); and now call showPopupSemaphoreSlim.WaitAsync() before each Navigation.PushModalAsync() / Shell.GotoAsync() method call. This ensures we wait until the modal page has finished pushing before we ask MAUI to push a new modal page.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

Additional information

This is more likely a bug internally in MAUI, as this SemaphoreSlim is not needed on Android.

@TheCodeTraveler
TheCodeTraveler removed the request for review from Copilot June 5, 2026 22:37
Copilot AI review requested due to automatic review settings June 5, 2026 22:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a race condition when multiple popups are shown concurrently by serializing popup navigation so PushModalAsync() / Shell.GoToAsync() calls don’t overlap.

Changes:

  • Added a shared SemaphoreSlim to gate popup display navigation.
  • Wrapped INavigation.PushModalAsync(...) and Shell.GoToAsync(...) calls with semaphore WaitAsync() / Release().

Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs
Comment thread src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs
Comment thread src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@TheCodeTraveler TheCodeTraveler changed the title Add showPopupSemaphoreSlim Prevent Race Condition Allowing Simultaneous Calling of Navigation.PushModalAsync() / Shell.GotoAsync() in PopupExtensions Jun 5, 2026
@TheCodeTraveler
TheCodeTraveler merged commit adf7902 into main Jun 6, 2026
10 checks passed
@TheCodeTraveler
TheCodeTraveler deleted the Fix-Issue-3192 branch June 6, 2026 03:10
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Concurrently produced popups cannot be closed (iOS)

3 participants