-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fixed hot reload/restart crashes after closing browser tab on web-server device #177026
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
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.
Code Review
This pull request addresses a crash that occurs during hot reload/restart on web-server devices after a browser tab is closed. The changes introduce try-catch blocks to handle exceptions during hot reload and restart operations. A new helper method, _handleNoClientsAvailableErrorIfFound, is added to specifically detect "No clients available" errors from DWDS by checking the error message string. When this error is detected, another new method, _invalidateConnection, is called to reset connection-related state, preventing the crash. My review includes suggestions to refactor duplicated error handling logic and to replace a magic string with a constant for better maintainability.
packages/flutter_tools/lib/src/isolated/resident_web_runner.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/lib/src/isolated/resident_web_runner.dart
Outdated
Show resolved
Hide resolved
srujzs
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.
Thanks! I'd consider adding a test as well where we close Chrome and then run a restart and/or reload.
| await _vmService.service.callMethod(hotRestartMethod); | ||
| try { | ||
| await _vmService.service.callMethod(hotRestartMethod); | ||
| } on Exception catch (e) { |
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.
Hmm, can we instead put this in the response from callMethod in DWDS? I believe we could place this in the json. My concern is mostly that this exception handling is brittle. If we ever decide to change the exception text, we'd end up breaking Flutter. Additionally, if some other unrelated exception happens to have this text, we'd be treating the error incorrectly. Similarly, in reloadSources, we may want _performWebSocketHotReload to return an error value if there are no clients that we can then encode in the ReloadReport rather than directly throwing and catching.
I think it's just a bit cleaner to encode errors/exceptions we can recover from in the response rather than catching errors and then checking for the text.
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.
Thanks for the suggestion! makes sense to me. I’ve made the corresponding changes in DWDS in this PR: dart-lang/webdev#2699, and updated the code here accordingly. I also added a test case to cover this scenario.
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.
Thanks for the changes and tests! It looks like Ben has some comments on the right error to bubble up on the DWDS PR. I'm guessing some of the code here will change after that so I'll re-review then.
| _logger.printTrace('No browser clients currently connected'); | ||
| status.stop(); | ||
| _logger.printStatus(kNoClientConnectedMessage); | ||
| return OperationResult.ok; |
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.
Should this be ok? Or are we doing this to suppress an error?
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.
Yes, that’s right. That’s currently what we’re doing when attempting a hot reload without the initial DWDS connection. We do this to exit the method early before running into an error.
For reference: resident_web_runner.dart#L492
srujzs
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 with the DWDS changes, thanks!
|
Failed to create CP due to merge conflicts. |
…on web-server device (flutter/flutter#177026)
…on web-server device (flutter/flutter#177026)
flutter/flutter@891d7d5...2d34167 2025-10-20 [email protected] Cleanup create_updated_flutter_deps.py a bit (flutter/flutter#177162) 2025-10-20 [email protected] Fixed hot reload/restart crashes after closing browser tab on web-server device (flutter/flutter#177026) 2025-10-20 [email protected] Roll Skia from 0a3ace6fde82 to ed4294faecde (2 revisions) (flutter/flutter#177249) 2025-10-20 [email protected] Add DropdownMenu.decorationBuilder (flutter/flutter#176264) 2025-10-20 [email protected] Roll Skia from 05e2f42f533d to 0a3ace6fde82 (1 revision) (flutter/flutter#177242) 2025-10-20 [email protected] Roll Skia from 89abc5393317 to 05e2f42f533d (1 revision) (flutter/flutter#177238) 2025-10-20 [email protected] [ios][engine] Fix autofill context cleanup and view lifecycle management (flutter/flutter#173598) 2025-10-20 [email protected] Fix Image.network not using cache when headers are specified (flutter/flutter#176831) 2025-10-19 [email protected] Roll Dart SDK from a66f334fee2a to 2cd2106f2cef (4 revisions) (flutter/flutter#177190) 2025-10-19 [email protected] Roll Skia from 2d424175a481 to 89abc5393317 (1 revision) (flutter/flutter#177235) 2025-10-19 [email protected] Make sure that a ListTile doesn't crash in 0x0 environment (flutter/flutter#176176) 2025-10-19 [email protected] Make sure that a DropdownButton doesn't crash in 0x0 environment (flutter/flutter#174880) 2025-10-19 [email protected] Roll Skia from 899155871d29 to 2d424175a481 (1 revision) (flutter/flutter#177229) 2025-10-19 [email protected] Roll Skia from b864c56efb66 to 899155871d29 (1 revision) (flutter/flutter#177227) 2025-10-19 [email protected] Roll Fuchsia Linux SDK from M8WT2GMY46e_0fFho... to tKrvmvTOQITL81oOC... (flutter/flutter#177223) 2025-10-19 [email protected] Roll Skia from 0992b560454f to b864c56efb66 (1 revision) (flutter/flutter#177222) 2025-10-18 [email protected] Fix HEIF decoding (flutter/flutter#176860) 2025-10-18 [email protected] Roll Skia from 74df18176924 to 0992b560454f (1 revision) (flutter/flutter#177217) 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] 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
… on web-server device (#177456) **Impacted Users:** Flutter web developers using the `web-server` device for hot reload/restart. **Impact Description:** Hot reload/restart crashes when the browser tab is closed, causing “Bad state: No element” errors and breaking the DWDS connection. **Workaround:** Rerun the app. **Risk:** Low — changes only affect hot reload/restart handling when no clients are connected. **Test Coverage:** Yes — covered by automated integration tests and verified with manual testing across reload/restart scenarios. **Validation Steps:** 1. run the app on webserver `flutter run -d web-server` 2. open the url 3. do hot reload 4. close the browser 5. do hot reload You should see a warning `WebSocketProxyService: No clients available.` along with `Recompile complete. No client connected.` printed in the console. The app should no longer crash. **Merged PR:** #177026 **Changes in DWDS (Parent PR):** [https://github.com/dart-lang/webdev/pull/2699](https://github.com/dart-lang/webdev/pull/2699) Fixes #174791
…ver device (flutter#177026) This PR fixes crashes during hot reload/restart operations on web-server devices that occur when browser tabs are closed. Previously, the VM service would throw "Bad state: No element" errors when attempting operations with no connected clients. The fix introduces graceful handling on both sides: DWDS now catches NoClientsAvailableException in its hot reload/restart operations and returns structured JSON responses with a noClientsAvailable boolean flag instead of throwing exceptions. Flutter Tools reads this flag via a helper method _checkNoClientsAvailable() and handles the scenario gracefully by displaying "Recompile complete. No client connected." while preserving the DWDS connection to automatically support browser reconnections without requiring a full restart of the Flutter tools. Fixes: flutter#174791 Changes in DWDS (Parent PR): dart-lang/webdev#2699 Follow up bug: dart-lang/sdk#61757
This PR fixes crashes during hot reload/restart operations on web-server devices that occur when browser tabs are closed. Previously, the VM service would throw "Bad state: No element" errors when attempting operations with no connected clients. The fix introduces graceful handling on both sides: DWDS now catches NoClientsAvailableException in its hot reload/restart operations and returns structured JSON responses with a noClientsAvailable boolean flag instead of throwing exceptions. Flutter Tools reads this flag via a helper method _checkNoClientsAvailable() and handles the scenario gracefully by displaying "Recompile complete. No client connected." while preserving the DWDS connection to automatically support browser reconnections without requiring a full restart of the Flutter tools.
Fixes: #174791
Changes in DWDS (Parent PR): dart-lang/webdev#2699
Follow up bug: dart-lang/sdk#61757