Skip to content

Refactor devicelab bin/run.dart and other cleanup - #96320

Merged
fluttergithubbot merged 2 commits into
flutter:masterfrom
Hixie:devicelabcleanup
Jan 10, 2022
Merged

fluttergithubbot merged 2 commits into
flutter:masterfrom
Hixie:devicelabcleanup

Conversation

@Hixie

@Hixie Hixie commented Jan 7, 2022

Copy link
Copy Markdown
Contributor
  • Refactor of bin/run.dart to remove the global variables. This caught some unused arguments, which are now removed, and made some ambiguous-looking code with global variables that were shadowing each other simpler to reason about. It also allowed a bunch of !s to be removed.

  • Introduced --terminate-stray-dart-processes argument so that tests can set --no-terminate-stray-dart-processes so that they can avoid terminating each other when tests are run with -j > 1.

  • Cleanup up some console output.

  • Removed the runProcessCleanup magic from tests.

  • Changed the killProcess implementation to use Process.killPid rather than deferring to another process.

  • Renamed localEngine to localEngineFromEnv to make it clearer what it did. (Ditto another nearby getter.)

Comment thread dev/devicelab/bin/run.dart Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I prefer seeing these defined somewhere outside of main, or even in its own file - although I'm not sure there's any really great solution here, since that ends up meaning a reader might not have a clear idea of what arguments are defined and what their types/expected values are.

Reason for preferring outside of main is that this is 100+ lines of configuration/documentation that I have to scroll through to get to the meat of what main is doing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

totally reasonable; I'll move it back into its own function but with more of a functional style rather than the global variables style from before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't work on Windows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(And Windows historically has been our biggest culprit for this kind of problem, especially since leaked processes can lock files something else wants/needs to delete).

Last time I brought this up with anyone from the VM team, it seems like a fundamental limitation on the API offered by windows. Hence the delegation to taskkill.exe which generally does a better job (but is not really suitable for use by the Dart VM as API surface IMO).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

roger. Is there an issue tracking this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

neither of those seem that problematic here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@aam see the linked bugs in #96320 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dnfield I looked at those - they seem to be about wrong return value or lack of waiting, they don't mention that killPid doesn't actually terminate given process.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahhh that part is a bit harder - but my recollection is that on Windows I would sometimes see a process that would only terminate if the /f flag was passed to taskkill.exe, and Dart had no equivalent way of doing the force part.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dart also has no way of waiting for the process to terminate, so we don't know if we're continuing execution after the process has finished or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, we could make killPid to wait for the process to exit. Some processes might take longer to exit, which will block this call too. Alternatively if caller insists on waiting it supposedly could call killPid until it returns false.

Would be nice if there was a repro for when killPid didn't actually work and you had to resort to shelling taskkill.exe

@dnfield dnfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Process.killPid isn't appropriate for use on Windows.

* Refactor of bin/run.dart to remove the global variables. This caught some unused arguments, which are now removed, and made some ambiguous-looking code with global variables that were shadowing each other simpler to reason about. It also allowed a bunch of `!`s to be removed.

* Introduced `--terminate-stray-dart-processes` argument so that tests can set `--no-terminate-stray-dart-processes` so that they can avoid terminating each other when tests are run with `-j` > 1.

* Cleanup up some console output.

* Removed the `runProcessCleanup` magic from tests.

* Changed the `killProcess` implementation to use `Process.killPid` rather than deferring to another process.

* Renamed `localEngine` to `localEngineFromEnv` to make it clearer what it did. (Ditto another nearby getter.)
@Hixie

Hixie commented Jan 10, 2022

Copy link
Copy Markdown
Contributor Author

Updated PR with suggested fixes (and more refactoring that it pushed me into).

@dnfield dnfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: contributor-productivity Team-specific productivity, code health, technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants