Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flutter] Re-enable unhandled error reporting
This re-enables unhandled Dart error handling in Flutter applications, which was removed in a76b958. The error handling as originally landed was unsafe. Specifically, in the case where the unhandled error handler was triggered during shutdown, there was a race condition which could cause a crash in the following scenario: 1. Runner::OnApplicationTerminate() is triggered, which posts a task to the application's platform thread will free the Application instance and terminate the platform thread. 2. Before that task is serviced, the unhandled error handler is called (by hooks.dart -> window.cc -> ui_dart_state.cc) on the UI thread. 3. The kill task is serviced and the Application dtor and Thread::Quit() are called, terminating the platform thread. 4. The unhandled error handler attempts to post a task to the platform thread, whose thread was killed in step 3. This triggers a crash. Fixing this requires a mechanism for the message loop to know that the associated thread has been terminated out from under it. This patch adds mitigation for this scenario, but remains non-threadsafe/racy. We pass the unhandled error handler a weak pointer to the Application and check it before posting a task to the platform thread. This has two issues: 1. WeakPtr isn't threadsafe, and assumes that all operations occur on a single thread. We're checking its value (which is mutated on the platform thread) on the UI thread without synchronization. 2. Even with a guarantee that the WeakPtr state were synchronized, there's a window between when we check the weak pointer and when we post to the platform thread in which application shutdown and thread destruction may occur. This unsafe mitigation is being landed in order to unblock a high priority bug (FL-256) on a short schedule, and a proper refactoring will be required to make this properly threadsafe. Change-Id: If60d1d3ca5799d82597f8a3acc4ddd3871058972 Ported from Topaz tree.
- Loading branch information