Skip to content

Fix indefinite wait in InitializeApplicationAsync when application terminates early#9851

Closed
Copilot wants to merge 1 commit intou/xiaoyun/fix#2630184from
copilot/sub-pr-9850
Closed

Fix indefinite wait in InitializeApplicationAsync when application terminates early#9851
Copilot wants to merge 1 commit intou/xiaoyun/fix#2630184from
copilot/sub-pr-9850

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 14, 2025

InitializeApplicationAsync waits indefinitely for named pipe connection via GetUpdateCapabilitiesAsync. If the application terminates before establishing the pipe, Hot Reload hangs forever.

Changes:

  • Cancellation propagation: Pass CancellationToken through session lifecycle, from TryCreatePendingSessionAsyncApplyLaunchVariablesAsyncInitializeApplicationAsync
  • Workaround for non-cancellable client: Use WithCancellation() in DeltaApplier.InitializeApplicationAsync to force cancellation since DefaultHotReloadClient.GetUpdateCapabilitiesAsync() ignores the token
  • Race condition mitigation: Add ReentrantSemaphore to ProjectHotReloadSession to serialize StartSessionAsync/StopSessionAsync calls
  • Process lifecycle handling: Set EnableRaisingEvents before subscribing to Process.Exited to avoid missing early termination events
  • Session cleanup: Extract RemoveSessionState method and ensure StopSessionAsync is always called even when StartSessionAsync hasn't completed

Example flow:

// Session state owns cancellation
HotReloadSessionState sessionState = new(RemoveSessionState, _threadingService);

// Token propagates through initialization
await projectHotReloadSession.ApplyLaunchVariablesAsync(
    environmentVariables, 
    sessionState.CancellationToken);  // Was: default

// Process exit triggers cancellation
process.Exited += (sender, e) => DisposeSessionStateAndStopSession(sessionState);
// → sessionState.Dispose() → _cancellationTokenSource.Cancel()
// → InitializeApplicationAsync unblocks via WithCancellation()

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix cancellation management in InitializeApplicationAsync Fix indefinite wait in InitializeApplicationAsync when application terminates early Nov 14, 2025
@drewnoakes drewnoakes deleted the copilot/sub-pr-9850 branch November 14, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants