Skip to content

Resume isolate before terminating tests to prevent flutter_tester leaks in integration tests#45248

Merged
DanTup merged 6 commits intoflutter:masterfrom
DanTup:prevent-leaked-flutter-tester
Nov 26, 2019
Merged

Resume isolate before terminating tests to prevent flutter_tester leaks in integration tests#45248
DanTup merged 6 commits intoflutter:masterfrom
DanTup:prevent-leaked-flutter-tester

Conversation

@DanTup
Copy link
Copy Markdown
Contributor

@DanTup DanTup commented Nov 20, 2019

When running integration tests locally I noticed that flutter_tester processes were being leaked. This is because during some of the tests the Flutter isolate is left paused and when we try to tear down (by sending SIGTERM) the output of the process says

Waiting for current test to finish
Press Ctrl+C again to terminate

Since the process doesn't quit within 10s, we then send SIGTERM which terminates the process and no cleanup is performed (so the child flutter_tester process is left). Sending a second SIGTERM did not resolve the issue in my testing because it also resulted in an unclean shutdown.

This probably fixes #26350, though I don't think it's a perfect fix since other code that terminates while paused (for example the user clicking Stop in the IDE while at a breakpoint) could still leak these processes - I don't think that's really a Flutter issue though (it's likely a package:test issue, or limitation that the IDEs should consider).

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Nov 20, 2019
@fluttergithubbot
Copy link
Copy Markdown
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@DanTup DanTup added the a: tests "flutter test", flutter_test, or one of our tests label Nov 20, 2019
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.

indentation?

Copy link
Copy Markdown
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm w/ indentation fix.

@christopherfujino
Copy link
Copy Markdown
Contributor

tools_tests are failing, can you try rebasing on ToT? this might have been fixed upstream.

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

Hmm, the failure does seem to be caused by this change - but I don't understand why the try/catch seems to be being ignored here and the error still thrown:

Screenshot 2019-11-25 at 10 26 53 am

The same code in a simple command line app seems to behave as I'd expect (the catch block executes). Is this a bug or am I overlooking something?

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

I've opened dart-lang/sdk#39513 about the caught exception that's still failing the test (it's possible it's my bug, but I can't come up with an explanation that makes sense to me).

I'll see if I can find a better way to work around it here for now.

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

I've rebased on latest code, fixed the indenting and also added a null check to avoid trying to resume when there's no VM service. The tests seem to all pass locally, though I'm still confused by the behaviour of the catch block - I may come back and tweak this in a future PR based on the response to dart-lang/sdk#39513.

@zanderso
Copy link
Copy Markdown
Member

If resume().timeout(defaultTimeout) might leak an error into the containing Zone (via an unawaited Future or microtask), you can use asyncGuard() to make sure it is caught where you want it to be caught.

However if resume().timeout(defaultTimeout) is in the tool codebase, the preferred solution is to not leak the error.

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

I was able to reproduce it without any zones in dart-lang/sdk#39513 (and without the timeout firing). It feels like a bug, but I'm not sure 🤷‍♂️

@zanderso
Copy link
Copy Markdown
Member

I left a comment on dart-lang/sdk#39513.

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

I pushed 5207952 which changes the timeout code (which aimed to print a warning when an action took too long, including all of the messages that went over the API in the meantime if they're not already being printed) to use a Timer which is cancelled if the future completes.

This seems to resolve the issue - exceptions in resume are now handled and don't fail tests.

@DanTup
Copy link
Copy Markdown
Contributor Author

DanTup commented Nov 25, 2019

Looks like Cirrus builds aren't running for this PR again 😞

@fkorotkov - could be another instance of 404s from GH?

@fkorotkov
Copy link
Copy Markdown
Contributor

@DanTup there was another issue this time. I've poked around and found that GH timed out while delivering the webhook. Cirrus' metrics looks fine around that time so will investigate more to see on which end this happened. In the meantime I've manually redelivered the webhook.

@DanTup DanTup requested a review from zanderso November 26, 2019 09:17
@DanTup DanTup merged commit 459c7fb into flutter:master Nov 26, 2019
@DanTup DanTup deleted the prevent-leaked-flutter-tester branch November 26, 2019 17:05
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: tests "flutter test", flutter_test, or one of our tests tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leaked flutter_tester processes are leaking memory and cause 3xhead flakiness

6 participants