Skip to content

[flutter_tools] Wait for TCP server socket to close in DaemonServer.run() - #193714

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
matasb-google:fix-daemon-server-await
Oct 6, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
matasb-google:fix-daemon-server-await

Conversation

@matasb-google

Copy link
Copy Markdown
Contributor

Restores await subscription.asFuture<void>(); before await subscription.cancel(); in DaemonServer.run(), which was inadvertently removed in #192830. Without awaiting the subscription future, flutter daemon --listen-on-tcp-port immediately cancels the ServerSocket listener and exits right after binding.

Part of #188471

Pre-launch Checklist

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 2, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the DaemonServer to wait for the server socket stream to close by awaiting subscription.asFuture() before cancelling the subscription, and adds a corresponding test. The review feedback suggests wrapping the await in a try-finally block to ensure the subscription is always cancelled even if an error occurs on the stream.

Comment on lines 224 to 225
await subscription.asFuture<void>();
await subscription.cancel();

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.

medium

If an error occurs on the stream, subscription.asFuture<void>() will complete with that error immediately. Since cancelOnError is false by default, the subscription will remain active and leak resources because subscription.cancel() is bypassed when the error is thrown.

Wrapping the await in a try-finally block ensures that the subscription is always properly cancelled.

    try {
      await subscription.asFuture<void>();
    } finally {
      await subscription.cancel();
    }

@matasb-google

Copy link
Copy Markdown
Contributor Author

@bkonyi - This reverts your change, which I think was unintentional. Please take a look.

@bkonyi bkonyi added the CICD Run CI/CD label Oct 5, 2026
@bkonyi
bkonyi self-requested a review October 5, 2026 16:06

@bkonyi bkonyi 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.

Thanks for catching this and adding a test!

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 5, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 5, 2026
@auto-submit

auto-submit Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/193714, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@bkonyi
bkonyi requested a review from chingjun October 5, 2026 16:12
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 6, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Oct 6, 2026
Merged via the queue into flutter:master with commit e79240e Oct 6, 2026
34 of 35 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants