[dotnet watch] fix deadlock on iOS with UIKitSynchronizationContext#54023
Open
jonathanpeppers wants to merge 1 commit intorelease/10.0.4xxfrom
Open
[dotnet watch] fix deadlock on iOS with UIKitSynchronizationContext#54023jonathanpeppers wants to merge 1 commit intorelease/10.0.4xxfrom
UIKitSynchronizationContext#54023jonathanpeppers wants to merge 1 commit intorelease/10.0.4xxfrom
Conversation
…text On iOS with CoreCLR, UIKitSynchronizationContext is installed before startup hooks run. Listener.Listen() calls GetAwaiter().GetResult() on the main thread, and await continuations try to post back to the blocked UI thread, causing a deadlock. Fix by adding ConfigureAwait(false) to awaits in the startup hook's call chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a deadlock in dotnet watch Hot Reload on iOS/CoreCLR caused by UIKitSynchronizationContext being installed before startup hooks run, combined with synchronous blocking (GetAwaiter().GetResult()) during startup-hook initialization.
Changes:
- Add
ConfigureAwait(false)to awaited operations in the startup-hook initialization call chain withinListener. - Add
ConfigureAwait(false)to awaited operations inWebSocketTransportsend/receive/connect paths to avoid resuming onto the UISynchronizationContext.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Dotnet.Watch/HotReloadAgent.Host/WebSocketTransport.cs | Prevents WebSocket connect/send/receive continuations from attempting to marshal back to a potentially-blocked UI thread. |
| src/Dotnet.Watch/HotReloadAgent.Host/Listener.cs | Prevents initialization/update-processing continuations from attempting to resume on the UI SynchronizationContext during the synchronous startup-hook initialization phase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On iOS with CoreCLR,
UIKitSynchronizationContextis installed before startup hooks run.Listener.Listen()callsGetAwaiter().GetResult()on the main thread, and await continuations try to post back to the blocked UI thread, causing a deadlock. Fix by addingConfigureAwait(false)to awaits in the startup hook's call chain. On Android, just due to startup ordering theSynchronizationContextwas not set.I didn't think of a way we could test this easily -- I basically built the dotnet/macios repo and copied dotnet-watch files on top to manually test. An end-to-end test in the dotnet/macios repo might be the best place.
With these changes in place:
I can see it working on a net11.0-ios project in an iOS simulator: