Skip to content

Conversation

@bkonyi
Copy link
Contributor

@bkonyi bkonyi commented Nov 11, 2025

Without this change, if multiple asynchronous exceptions are thrown while processing an exception, multiple exception analytics events can be sent for a single process crash, skewing crashlytics data.

Fixes #178318

Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, the shutdown hooks can be run multiple
times and multiple exception analytics events can be sent for a single
process crash, skewing crashalytics data.

Fixes #178318
@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Nov 11, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to ensure that unhandled tool exceptions are processed only once, preventing duplicate shutdown hook executions and analytics events. This is achieved by introducing a _alreadyHandlingToolError future that acts as a guard. The implementation is clean and effectively solves the described problem. A new test case has been added to verify this fix by simulating multiple asynchronous exceptions and asserting that only a single analytics event is sent. My review includes a couple of minor suggestions in the new test code to improve its clarity and maintainability.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2025
// This flutterVersion disables crash reporting.
flutterVersion: '[user-branch]/',
reportCrashes: true,
shutdownHooks: ShutdownHooks(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we verify shutdown hooks are only called once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the ShutdownHooks implementation, we actually guard against running the hooks more than once as it's possible to invoke exitWithHooks after returning from a command and for it to be invoked due to an outstanding asynchronous event that throws.

I've updated the PR description to reflect this. The main thing we're testing here is that we don't try and sent multiple events due to asynchronous exceptions being thrown in quick succession. I've verified this test fails without the fix.

@reidbaker
Copy link
Contributor

Are you at all worried about the loss of data by throwing the first tool error we see and none of the rest?

@bkonyi
Copy link
Contributor Author

bkonyi commented Nov 12, 2025

Are you at all worried about the loss of data by throwing the first tool error we see and none of the rest?

No, I don't think so. Errors thrown after the initial error are likely due to a cascading failure, and we'd have to explicitly check for multiple reports (possibly with different stack traces) from an individual client within a short timeframe to even identify if multiple exceptions were thrown during a crash.

Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

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

LGTM

@auto-submit auto-submit bot added this pull request to the merge queue Nov 12, 2025
Merged via the queue into master with commit 162bf57 Nov 12, 2025
151 checks passed
@auto-submit auto-submit bot deleted the fix_multiple_crash_reports branch November 12, 2025 18:55
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 12, 2025
@bkonyi bkonyi added cp: beta cherry pick this pull request to beta release candidate branch cp: stable cherry pick this pull request to stable release candidate branch labels Nov 13, 2025
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Nov 13, 2025
Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, multiple exception analytics events can
be sent for a single process crash, skewing crashlytics data.

Fixes flutter#178318
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Nov 13, 2025
Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, multiple exception analytics events can
be sent for a single process crash, skewing crashlytics data.

Fixes flutter#178318
IvoneDjaja pushed a commit to IvoneDjaja/flutter that referenced this pull request Nov 22, 2025
Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, multiple exception analytics events can
be sent for a single process crash, skewing crashlytics data.

Fixes flutter#178318
mboetger pushed a commit to mboetger/flutter that referenced this pull request Dec 2, 2025
Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, multiple exception analytics events can
be sent for a single process crash, skewing crashlytics data.

Fixes flutter#178318
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Without this change, if multiple asynchronous exceptions are thrown
while processing an exception, multiple exception analytics events can
be sent for a single process crash, skewing crashlytics data.

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

Labels

cp: beta cherry pick this pull request to beta release candidate branch cp: stable cherry pick this pull request to stable release candidate branch tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants