-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[Embedder] Detect and ignore stale task runner tasks #163129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
59ffdfa to
7577468
Compare
|
Added a test that isolates the issue (always crashes) without the fix. |
|
Looking at the test, it is now obvious that the reason why this wasn't a problem before: Engine shutdown happens on platform thread, and thus checking the engine being non The engine is never invalid when calling For UI thread the situation is different. We can't block UI thread while shutting down the engine, because during engine shutdown tasks are scheduled on UI thread. So there is a possibility for UI thread to call This would only be a problem in practice if embedder specifies custom UI task runner that is not same as platform task runner. This doesn't seem a likely scenario, but the API allows it so we should make sure it works correctly. |
|
Thanks for the quick response @knopp. I'm going to defer to @jonahwilliams for review. |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5524f63 to
876f970
Compare
Fixes #163104
The core issue is that
EmbedderTaskRunnercan schedule things in advance, but there is no checking if the task is stale when executing it. It is possible thatFlutterEngineRunTaskwill attempt to run the task on engine that is non null but already being deallocated.This in not a problem for raster and platform task runners, because raster task runner shouldn't have any scheduled tasks after shutdown and platform task runner executes the shutdown process, so the pointer is always either valid or null, but it is an issue for custom
ui_task_runner, because it may be callingFlutterEngineRunTaskwith engine pointer that is not yet null but already shutting down.The proposed solution is to assign a unique identifier for each
EmbedderTaskRunner, use this identifier as therunnerfield insideFlutterTaskinstead of casting the address of the runner, and verify that this identifier is valid insideFlutterEngineRunTaskbefore calling anything on the engine.Special care needs to be done to not invalidate the unique identifier while
ui_task_runneris running a task as it may lead to raciness. SeeEmbedderEngine::CollectThreadHost().Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.