-
Notifications
You must be signed in to change notification settings - Fork 6k
Guard against Dart timeline API calls invoked during Dart_Cleanup #24007
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
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.
Other than the bit about the use of the shared-exclusive lock, lgtm.
runtime/dart_vm_initializer.cc
Outdated
// APIs. This mutex must be held during calls to Dart_Initialize and | ||
// Dart_Cleanup so that Dart API calls on other threads can be protected | ||
// against a concurrent call to Dart_Cleanup. | ||
static std::mutex gDartInitializerMutex; |
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.
We won't have a global lock on timeline traces with a shared-exclusive lock here. Shared access on tracking and exclusive access in the Initialize
and Cleanup
. We can't use std::shared_mutex
because of iOS libc++
but we have fml/synchronization/SharedLock
for that purpose.
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.
done
2b3a991
to
bfcc7d2
Compare
Presubmits are mad about GN formatting. |
bfcc7d2
to
582ca71
Compare
582ca71
to
d7451ce
Compare
There is one flake that I filed a report for. The Windows failure is real and indicates you forgot to import |
5253253
to
5c39fab
Compare
Looked at the runtime_unittest failures and found that they were caused by deadlocks. This PR attempted to use a lock around the calls to SInce the thread calling I changed this PR to use a flag to indicate whether This is a race - if a thread sees that the flag is set and proceeds to call I don't think there is a way to make this completely safe given the current design of the Dart APIs. It might be valuable for Dart to provide an API for setup and cleanup of the timeline that is separate from other Dart VM subsystems. |
I filed dart-lang/sdk#44814 |
The Dart timeline is not thread safe if an engine thread that is not controlled by Dart calls Dart_TimelineEvent while another thread is calling Dart_Cleanup. Fixes flutter/flutter#74134
5c39fab
to
fa8d9c2
Compare
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.
As you mentioned in the comment, that flag is inherently racy. I fear we may just be kicking the can down the road. But, if we are following up on a fix for it and this ameliorates some of the impact caused by flakes, lets land this for now.
The Dart timeline is not thread safe if an engine thread that is not controlled by Dart calls Dart_TimelineEvent while another thread is calling Dart_Cleanup. Fixes flutter/flutter#74134
The Dart timeline is not thread safe if an engine thread that is not
controlled by Dart calls Dart_TimelineEvent while another thread is
calling Dart_Cleanup.
Fixes flutter/flutter#74134