Skip to content

flutter_tool crash handler should not report multiple crashes for a single process #178318

@bkonyi

Description

@bkonyi

While debugging #178317, it became clear that it's possible for multiple crash events to be sent for a single process while the tool's shutdown hooks are executing.

Once the root error handler in the tool encounters an exception, it reports the crash to our crash analytics service before running all registered shutdown hooks. Once these shutdown hooks complete, the tool exits.

However, since the shutdown hooks can be asynchronous, it's possible for additional exceptions to be thrown due to the introduction of asynchronous gaps. In the referenced issue, the original exception was thrown from a file watcher callback that was processing files after a flutter pub get, resulting in exceptions being thrown from the same location repeatedly while the tool was shutting down. This caused the root error handler to be invoked repeatedly, causing multiple crash reports to be sent for a single process and the shutdown hooks to be invoked again. Eventually, the tool is able to exit successfully, but only after reporting multiple crashes.

In order to prevent the root error handler from attempting to report additional crashes while executing the shutdown hooks, we should prevent the error handler from being reentrant and return from the handler immediately if we're already in the process of shutting down the tool due to an exception.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listteam-toolOwned by Flutter Tool teamtriaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions