-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fixed race condition in PollingDeviceDiscovery. #145506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed race condition in PollingDeviceDiscovery. #145506
Conversation
6f9bd83 to
7e5b671
Compare
christopherfujino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice! How did you find this bug, btw?
|
FYI @vashworth |
There are two issues in the previous implementation: 1. `_populateDevices` will return the devices from `deviceNotifier` if it had been initialized, assuming that once it's initialized, it has been properly populated. That assumption is not true because calling getters like `onAdded` would initialize `deviceNotifier` without populating it. 2. `deviceNotifier` instance might be replaced in some cases, causing `onAdded` subscribers to lose any future updates. To fix (1), this commit added the `isPopulated` field in `deviceNotifier` as a more accurate flag to determine if we need to populate it. To fix (2), this commit made `deviceNotifier` a final member in `PolingDeviceDiscovery`.
7e5b671 to
05538ba
Compare
We found it because the tool is failing inconsistently for some of us internally, with an error message saying "device not found". For me, the reproduction rate is maybe ~10%, for some people it's higher (not sure why). The weird thing that caught our attention is that, even though it claimed that device is not found, the report generated right after the failure still contains that specific device id. So we traced the call stack and found this bug as a possible explanation. After this fix, I can no longer reproduce the issue by launching the app a bunch of times. So hopefully this is the only race condition :) |
flutter/flutter@18340ea...14774b9 2024-03-22 [email protected] Roll Flutter Engine from eba6e31498b8 to 09dadce76828 (1 revision) (flutter/flutter#145603) 2024-03-22 [email protected] Roll Flutter Engine from f9a34ae0b14f to eba6e31498b8 (1 revision) (flutter/flutter#145598) 2024-03-22 [email protected] Intensive `if` chain refactoring (flutter/flutter#145194) 2024-03-22 [email protected] Adds numpad navigation shortcuts for Linux (flutter/flutter#145464) 2024-03-22 [email protected] Roll Flutter Engine from 5a12de1beab7 to f9a34ae0b14f (1 revision) (flutter/flutter#145581) 2024-03-22 [email protected] Roll Flutter Engine from e2f324beac3b to 5a12de1beab7 (1 revision) (flutter/flutter#145578) 2024-03-22 [email protected] Replace `RenderBox.compute*` with `RenderBox.get*` and add `@visibleForOverriding` (flutter/flutter#145503) 2024-03-22 [email protected] Add some cross references in the docs, move an example to a dartpad example (flutter/flutter#145571) 2024-03-22 [email protected] Fix `BorderSide.none` requiring explicit transparent color for `UnderlineInputBorder` (flutter/flutter#145329) 2024-03-22 [email protected] Roll Flutter Engine from a46a7b273a5b to e2f324beac3b (1 revision) (flutter/flutter#145576) 2024-03-21 [email protected] Fix nullability of getFullHeightForCaret (flutter/flutter#145554) 2024-03-21 [email protected] Add a `--no-gradle-generation` mode to the `generate_gradle_lockfiles.dart` script (flutter/flutter#145568) 2024-03-21 [email protected] Roll Flutter Engine from 1b842ae58b3d to a46a7b273a5b (2 revisions) (flutter/flutter#145569) 2024-03-21 [email protected] Fixed race condition in PollingDeviceDiscovery. (flutter/flutter#145506) 2024-03-21 [email protected] Roll Flutter Engine from a2ed373fa70f to 1b842ae58b3d (1 revision) (flutter/flutter#145565) 2024-03-21 [email protected] Clarify AutomaticKeepAliveClientMixin semantics in build method (flutter/flutter#145297) 2024-03-21 [email protected] Eliminate more window singleton usages (flutter/flutter#145560) 2024-03-21 [email protected] `flutter test --wasm` support (flutter/flutter#145347) 2024-03-21 [email protected] Roll Flutter Engine from eb262e9c34db to a2ed373fa70f (2 revisions) (flutter/flutter#145556) 2024-03-21 [email protected] Roll Flutter Engine from bad4a30e1c75 to eb262e9c34db (1 revision) (flutter/flutter#145555) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
There are two issues in the previous implementation:
_populateDeviceswill return the devices fromdeviceNotifierif it had been initialized, assuming that once it's initialized, it has been properly populated. That assumption is not true because calling getters likeonAddedwould initializedeviceNotifierwithout populating it.deviceNotifierinstance might be replaced in some cases, causingonAddedsubscribers to lose any future updates.To fix (1), this commit added the
isPopulatedfield indeviceNotifieras a more accurate flag to determine if we need to populate it.To fix (2), this commit made
deviceNotifiera final member inPolingDeviceDiscovery.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.