Do not handle Dart isolate messages if the isolate is being shut down #57081
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a race that can happen if Dart invokes an isolate's message handling callback during isolate shutdown. The callback installed by Tonic will invoke a dispatcher set by the engine's DartIsolate::SetMessageHandlingTaskRunner, which will queue a message handling task to the designated task runner.
If the queued task runs after DartIsolate::Shutdown has been called, then Tonic's DartMessageHandler::OnHandleMessage will fail when it tries to enter the isolate.
DartIsolate will set a shutdown flag on the DartState when Dart invokes the isolate's shutdown callback. Tonic can avoid this race by checking that flag before proceeding with message handling.
Fixes flutter/flutter#160003