Repository navigation
[flutter_tools] Wait for TCP server socket to close in DaemonServer.run() - #193714
Conversation
There was a problem hiding this comment.
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.
| await subscription.asFuture<void>(); | ||
| await subscription.cancel(); |
There was a problem hiding this comment.
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();
}|
@bkonyi - This reverts your change, which I think was unintentional. Please take a look. |
bkonyi
left a comment
There was a problem hiding this comment.
Thanks for catching this and adding a test!
|
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.
|
…un() (flutter#193714) Restores `await subscription.asFuture<void>();` before `await subscription.cancel();` in `DaemonServer.run()`, which was inadvertently removed in flutter#192830. Without awaiting the subscription future, `flutter daemon --listen-on-tcp-port` immediately cancels the `ServerSocket` listener and exits right after binding. Part of flutter#188471 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Restores
await subscription.asFuture<void>();beforeawait subscription.cancel();inDaemonServer.run(), which was inadvertently removed in #192830. Without awaiting the subscription future,flutter daemon --listen-on-tcp-portimmediately cancels theServerSocketlistener and exits right after binding.Part of #188471
Pre-launch Checklist
///).