Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Dotnet.Watch/HotReloadAgent.Host/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ public Task Listen(CancellationToken cancellationToken)

try
{
// block execution of the app until initial updates are applied:
InitializeAsync(cancellationToken).GetAwaiter().GetResult();
// block execution of the app until initial updates are applied.
// Run on the thread pool (Task.Run) so that awaits inside InitializeAsync
// do not capture the calling thread's SynchronizationContext. Otherwise,
// on platforms where the startup-hook thread has a sync context (e.g. iOS,
// Android), the synchronous wait below would deadlock when an awaited
// continuation tries to resume on the same blocked thread.
Task.Run(() => InitializeAsync(cancellationToken), cancellationToken).GetAwaiter().GetResult();
Comment on lines +37 to +43
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The deadlock fix is important, but it isn’t currently covered by a regression test. Since the repo already has unit tests that instantiate Listener (e.g., test/Microsoft.Extensions.DotNetDeltaApplier.Tests/HotReloadClientTests.cs), consider adding a test that runs Listener.Listen from a thread with a non-null SynchronizationContext and uses a test Transport.SendAsync that performs an await (e.g., Task.Yield) to validate that initialization completes (i.e., no sync-context deadlock) within a timeout.

Copilot generated this review using guidance from repository custom instructions.
}
catch (Exception e)
{
Expand Down
Loading