Skip to content

Commit e300b37

Browse files
RELAND: [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter#192655)
Ensures temporary Chrome user profile directories created during web benchmarks are reliably deleted, and ensures benchmark child processes (Chrome, Shelf, and `flutter run`) are cleaned up when benchmarks complete or when interrupted with SIGINT/SIGTERM. Part of flutter#191316 _Tip for reviewers: Recommend viewing with "Hide whitespace" enabled (`?w=1`), as wrapping the task body in `try ... finally` re-indents the inner block._ I fixed the issue with the Chrome lifecycle that caused the original revert. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent bdb24b7 commit e300b37

3 files changed

Lines changed: 665 additions & 209 deletions

File tree

‎dev/devicelab/lib/framework/browser.dart‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Chrome {
8282
// If the Chrome process quits before it was asked to quit, notify the
8383
// error listener.
8484
_chromeProcess.exitCode.then((int exitCode) {
85-
if (!_isStopped) {
85+
if (!_isStopped && exitCode != 0) {
8686
_onError('Chrome process exited prematurely with exit code $exitCode');
8787
}
8888
});
@@ -92,7 +92,7 @@ class Chrome {
9292
///
9393
/// The [onError] callback is called with an error message when the Chrome
9494
/// process encounters an error. In particular, [onError] is called when the
95-
/// Chrome process exits prematurely, i.e. before [stop] is called.
95+
/// Chrome process exits prematurely, i.e. before [stop] or [disconnect] is called.
9696
static Future<Chrome> launch(
9797
ChromeOptions options, {
9898
String? workingDirectory,
@@ -167,7 +167,7 @@ class Chrome {
167167
///
168168
/// The [onError] callback is called with an error message when the Chrome
169169
/// process encounters an error. In particular, [onError] is called when the
170-
/// Chrome process exits prematurely, i.e. before [stop] is called.
170+
/// Chrome process exits prematurely, i.e. before [stop] or [disconnect] is called.
171171
static Future<Chrome> connect(
172172
io.Process chromeProcess,
173173
ChromeOptions options, {
@@ -270,10 +270,15 @@ class Chrome {
270270
await _debugConnection?.page.reload(ignoreCache: ignoreCache);
271271
}
272272

273-
/// Stops the Chrome process.
274-
void stop() {
273+
/// Disconnects from the Chrome process without killing it.
274+
void disconnect() {
275275
_isStopped = true;
276276
_tracingSubscription?.cancel();
277+
}
278+
279+
/// Stops the Chrome process.
280+
void stop() {
281+
disconnect();
277282
_chromeProcess.kill();
278283
}
279284
}

0 commit comments

Comments
 (0)