Repository navigation
[multicast_dns] Fix start returning early while another start is in progress - #55
rabiee-nasri wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates MDnsClient in multicast_dns to handle concurrent and failed initialization attempts by changing the _starting flag from a boolean to a Future<void>? and extracting the initialization logic into a private _start method. It also adds unit tests to verify these behaviors. The review feedback identifies an issue in the stop method where checking _started before _starting causes the method to return early instead of throwing a StateError when called during startup, and provides a suggestion to swap the order of these checks.
| void stop() { | ||
| if (!_started) { | ||
| return; | ||
| } | ||
| if (_starting) { | ||
| if (_starting != null) { | ||
| throw StateError('Cannot stop mDNS client while it is starting.'); | ||
| } |
There was a problem hiding this comment.
In the current implementation of stop(), the check if (!_started) is performed before if (_starting != null). Since _started is only set to true at the very end of the start process, _started is false while the client is starting. This means calling stop() while the client is starting will return early and silently ignore the call, rather than throwing the expected StateError as intended. Swapping the order of these checks ensures that attempting to stop the client while it is starting correctly throws a StateError.
| void stop() { | |
| if (!_started) { | |
| return; | |
| } | |
| if (_starting) { | |
| if (_starting != null) { | |
| throw StateError('Cannot stop mDNS client while it is starting.'); | |
| } | |
| void stop() { | |
| if (_starting != null) { | |
| throw StateError('Cannot stop mDNS client while it is starting.'); | |
| } | |
| if (!_started) { | |
| return; | |
| } |
|
@googlebot I signed it! |
…rogress A second call to MDnsClient.start made while the first was still running returned at once, so a caller could await start and then get a StateError from lookup. A failed start also left the client marked as starting, so later calls did nothing. Share the in-progress start between callers and clear it when it completes, so a failed start can be retried.
114c68c to
8c290eb
Compare
MDnsClient.startreturned immediately when another call tostartwas still in progress. A caller couldawait client.start()and then getBad state: mDNS client must be started before calling lookup.fromlookup, because the client was not started yet.A failed
start(for example when the socket cannot be bound) also left the client marked as starting, so every later call tostartdid nothing.Now the start that is in progress is kept as a future. Calls made while the client is starting return that future, and it is cleared when the start completes or fails, so a failed start can be retried. Calls made after the client is started are still ignored, as documented.
Fixes flutter/flutter#177246
Pre-Review Checklist
[vector_math]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2