Skip to content

Fix hang during shutdown in Flutter workspaces - #6016

Merged
DanTup merged 1 commit into
masterfrom
fix-daemon-hang
Mar 30, 2026
Merged

DanTup merged 1 commit into
masterfrom
fix-daemon-hang

Conversation

@DanTup

@DanTup DanTup commented Mar 30, 2026

Copy link
Copy Markdown
Member

It appears a recent change to VS Code started waiting up to around 5s for deactivate() to complete and showing a "Stopping extension hosts..." notification.

It also seems that our shutdown of the Flutter daemon was hanging, but until this change it was not visibile.

The issue seems to be that we explicitly called shutdown() in deactivate, but VS Code was also calling dispose() on everything. The results was that we send a call to shutdown() and waited for a response, but VS Code caused the process to be terminated and therefore the response never came and we waited indefinitely.

This change causes shutdown() to complete if either it gets a response or or the process exits, avoiding this race.

Fixes #6015

It appears a recent change to VS Code started waiting up to around 5s for `deactivate()` to complete and showing a "Stopping extension hosts..." notification.

It also seems that our shutdown of the Flutter daemon was hanging, but until this change it was not visibile.

The issue seems to be that we explicitly called `shutdown()` in deactivate, but VS Code was also calling `dispose()` on everything. The results was that we send a call to `shutdown()` and waited for a response, but VS Code caused the process to be terminated and therefore the response never came and we waited indefinitely.

This change causes `shutdown()` to complete if _either_ it gets a response or _or_ the process exits, avoiding this race.

Fixes #6015
@DanTup DanTup added this to the v3.132.0 milestone Mar 30, 2026
@DanTup DanTup added is bug fix in flutter Relates to running Flutter apps labels Mar 30, 2026
@DanTup
DanTup requested a review from Copilot March 30, 2026 17:15
@gemini-code-assist

This comment was marked as outdated.

@DanTup

DanTup commented Mar 30, 2026

Copy link
Copy Markdown
Member Author

/gemini review

Copilot AI left a comment

Copy link
Copy Markdown

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 shutdown hang in Flutter workspaces caused by a race between explicitly calling the Flutter daemon shutdown() during deactivate() and VS Code concurrently disposing/terminating the daemon process. It makes shutdown complete when either the shutdown response arrives or the process exits, preventing VS Code from waiting indefinitely and showing “Stopping extension hosts…”.

Changes:

  • Expose a shared processExit promise on StdIOService that resolves when the underlying process exits.
  • Update Flutter daemon shutdown() to await Promise.race() between daemon.shutdown response and processExit.
  • Remove the duplicated ProcessExitCodes/exit tracking from the tooling daemon process and reuse the shared type/export.

Reviewed changes

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

File Description
src/shared/services/tooling_daemon.ts Switches to the shared ProcessExitCodes export and removes the local exit completer.
src/shared/services/stdio_service.ts Adds processExit promise + exported ProcessExitCodes type to standardize exit tracking across services.
src/extension/flutter/flutter_daemon.ts Prevents shutdown hangs by racing daemon.shutdown against process exit and minor cleanup in dispose().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread src/extension/flutter/flutter_daemon.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors process exit handling by moving the processExit promise logic into the StdIOService base class, allowing for broader reuse. The FlutterDaemon.shutdown method was updated to be asynchronous and now uses Promise.race to prevent the shutdown process from hanging. Feedback was provided to maintain the use of curly braces for single-line if statements to ensure style consistency and prevent future errors.

Comment on lines +165 to 166
if (this.pingIntervalId)
clearInterval(this.pingIntervalId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency and to prevent potential issues when adding more statements, it's a good practice to always use curly braces for if statements, even for single-line blocks. The codebase has an inconsistent style regarding this, and moving towards a consistent style would improve maintainability.

Suggested change
if (this.pingIntervalId)
clearInterval(this.pingIntervalId);
if (this.pingIntervalId) {
clearInterval(this.pingIntervalId);
}

@DanTup
DanTup merged commit f102d26 into master Mar 30, 2026
29 checks passed
@DanTup
DanTup deleted the fix-daemon-hang branch March 30, 2026 17:28
@codecov

codecov Bot commented Mar 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.13%. Comparing base (5e86373) to head (4533241).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/extension/flutter/flutter_daemon.ts 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6016      +/-   ##
==========================================
+ Coverage   68.07%   68.13%   +0.05%     
==========================================
  Files         170      170              
  Lines       12912    12916       +4     
  Branches     2572     2573       +1     
==========================================
+ Hits         8790     8800      +10     
+ Misses       3662     3659       -3     
+ Partials      460      457       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in flutter Relates to running Flutter apps is bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Stopping extension hosts" takes a long time

2 participants