Skip to content

Conversation

@andrewkolos
Copy link
Contributor

@andrewkolos andrewkolos commented Aug 22, 2024

Fixes #153972 (unless the cause of #153064 (comment) happens to also prevent this fix from working).

In this PR, I've looked for all non-test call sites of ChromeConnection.getTabs and made sure are all wrapped in try blocks that handle IOException (HttpException is what we see in crash reporting, but I figure any IOException might as well be the same for all intents and purposes).

I plan on cherry-picking this the stable branch.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Comment on lines 611 to 619
late final ChromeTab? chromeTab;
try {
chromeTab = await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
return !chromeTab.url.startsWith('chrome-extension');
}, retryFor: const Duration(seconds: 5));
} on IOException {
// We were unable to unable to communicate with Chrome.
chromeTab = null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be caught by the recently added

} on HttpException catch (error, stackTrace) {
appFailedToStart();
_logger.printError('$error', stackTrace: stackTrace);
throwToolExit(kExitMessage);

However, I prefer trying to catch exceptions as close to the thrower as we can.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics are different whether this is caught at line 386 or 616. That is to say:

  1. should we be calling appFailedToStart() here?
  2. should we be printing to STDERR the error and stacktrace?
  3. should we be calling the more explicit HttpException here?
  4. on the other hand, should we be calling the more general IOException on line 386?

I'm genuinely asking, I don't know this code at all.

Copy link
Contributor Author

@andrewkolos andrewkolos Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good questions!

The semantics are different whether this is caught at line 386 or 616. That is to say:

  1. should we be calling appFailedToStart() here?

This would be consistent with my principal of failing as early as possible. appFailedToStart just sets the exit code for the runner to 1:

if (!_finished.isCompleted) {
_finished.complete(1);
}

which is read by various call sites trying to attach to a device.

TL;DR yeah we probably should be calling this (though it doesn't ultimately matter since we are exiting the tool anyway).

  1. should we be printing to STDERR the error and stacktrace?

I don't know. I notice that we don't do so for the other exception handlers. I'm guessing the reason we don't is that such a thing might be noisy for users.

Normally I would say that users could just rerun with -v to troubleshoot, but these kind of issues tend to be difficult to reproduce, so maybe we should log to stderr.

At the risk of digressing, I think it would be cool if the tool had a mechanism to prevent error details logs to a file. Imagine this:

$flutter run -d chrome
...
blah blah
...
Failed to connect to Chrome instance.

HttpException: Connection closed before full header was received, uri = http://localhost:52097/json

More error details were logged here: path/to/logfile.txt

I think something like this already happens when the tool crashes? We could do something similar to that sans sending a crash report.

To actually answer your question: yes, I've added some extra logging here. However, the tradeoff, again, is that users might waste their time reading noise they don't care about. Consider this, for example (but with a much, much longer stack trace):

Waiting for connection from debug service on Chrome...              9.7s
HttpException: uh oh!
#0      ResidentWebRunner.attach (package:flutter_tools/src/isolated/resident_web_runner.dart:616:9)
<asynchronous suspension>
#1      asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:24)
<asynchronous suspension>

Failed to connect to Chrome instance.
  1. should we be calling the more explicit HttpException here?

If we wish to be more conservative (which is worth considering since this would be CP'd to stable), then sure. In fact, this is probably the way to go (we probably wouldn't want to catch FileSystemExceptions, for example—as unlikely as they may be). Maybe we should also catch SocketException and whatnot here as well, but I'm content to wait until it shows up in crash reports before going ahead and fixing that.

  1. on the other hand, should we be calling the more general IOException on line 386?

I'm genuinely asking, I don't know this code at all.

Probably not, see my previous point.

@andrewkolos andrewkolos marked this pull request as ready for review August 23, 2024 00:36
Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beyond me, but at a high level it looks like the kind of thing that would catch this :)

@andrewkolos andrewkolos force-pushed the handle-exceptions-from-connecting-to-chrome branch 2 times, most recently from 26add34 to cee7482 Compare August 27, 2024 14:11
@andrewkolos andrewkolos force-pushed the handle-exceptions-from-connecting-to-chrome branch from cee7482 to bf8d3ef Compare August 27, 2024 14:17
@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 27, 2024

auto label is removed for flutter/flutter/153978, due to - The status or check suite Linux customer_testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2024
@andrewkolos andrewkolos added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2024
@auto-submit auto-submit bot merged commit 9ec2588 into flutter:master Aug 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2024
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
Fixes flutter#153972  (unless the cause of flutter#153064 (comment) happens to also prevent this fix from working).

In this PR, I've looked for all non-test call sites of `ChromeConnection.getTabs` and made sure are all wrapped in `try` blocks that handle `IOException` (`HttpException` is what we see in crash reporting, but I figure any `IOException` might as well be the same for all intents and purposes).

I plan on cherry-picking this the stable branch.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
auto-submit bot pushed a commit that referenced this pull request Sep 11, 2024
…ction.getTab` (#154380)

This is a custom hotfix patch to fix #154366 and #153064 on the stable channel. The reason for a custom patch rather than a bot-created PR is that the fixes on master were done by two sequential PRs (#153978 and #154366). This CP patch is also a subset of those changes (calls to Chrome when shutting down at the end of `flutter run -d chrome`).
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

3 participants