Skip to content
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

Fix threading-related crash in Cobalt telemetry. #689

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

joeltine
Copy link
Contributor

@joeltine joeltine commented Jun 22, 2023

Fix threading-related crash in Cobalt telemetry.

The Chromium metrics libraries require any calls to their public APIs to
be invoked on the same thread in which they were created. Similarly,
H5vcc JS callback need to be invoked on the V8 thread.

This was being violated as the H5vcc callbacks were being invoked by a
non-V8 thread and H5vccMetrics was trying to call metrics APIs from a V8
thread.

The fix is to store the task runners for the
CobaltMetricsServicesManager and H5vccMetrics instances and use those to
run any tasks that must be run in the targeted thread.

This approach required a slight refactoring to allow the top level
CobaltMetricsServicesManager to provide its own public API to interact
with the underlying metrics client on a targeted thread.

I also found this approach allowed me to just pass around a
RepeatingCallback for the upload handler and remove the abstract class
that was being used before (CobaltH5vccMetricsUploaderCallback).

Added a demo page to verify all the behavior is correct.

b/288252273

Change-Id: I878285894293f5faae409e477998b2073631f306

@joeltine joeltine changed the title Bootstrap and initialize telemetry in application startup Fix threading-related crash in Cobalt telemetry. Jun 22, 2023
@joeltine joeltine force-pushed the blackbox-and-demo branch 2 times, most recently from 8509dff to 785b5fd Compare June 22, 2023 16:25
@joeltine
Copy link
Contributor Author

FYI: this PR is based off #645 and makes a few tweaks on top of it. Happy to replace that PR with this one, if you'd prefer.

@joeltine joeltine marked this pull request as ready for review June 22, 2023 16:54
The Chromium metrics libraries require any calls to their public APIs to
be invoked on the same thread in which they were created. Similarly,
H5vcc JS callback need to be invoked on the V8 thread.

This was being violated as the H5vcc callbacks were being invoked by a
non-V8 thread and H5vccMetrics was trying to call metrics APIs from a V8
thread.

The fix is to store the task runners for the
CobaltMetricsServicesManager and H5vccMetrics instances and use those to
run any tasks that must be run in the targeted thread.

This approach required a slight refactoring to allow the top level
CobaltMetricsServicesManager to provide its own public API to interact
with the underlying metrics client on a targeted thread.

I also found this approach allowed me to just pass around a
RepeatingCallback for the upload handler and remove the abstract class
that was being used before (CobaltH5vccMetricsUploaderCallback).

Added demo to verify everything is working.

b/288252273

Change-Id: I8243b27a1853c65ac9d4fe11adc95a7f4da9ed51
@joeltine
Copy link
Contributor Author

FYI: Just rebased this on top of #645, which was submitted just recently.

Copy link
Contributor

@sherryzy sherryzy left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Just leave a one minor comment above.

@joeltine joeltine merged commit a89e9fb into youtube:main Jun 22, 2023
338 checks passed
@joeltine joeltine deleted the blackbox-and-demo branch June 22, 2023 20:37
@joeltine joeltine added the cp-24.lts.1+ Cherry Pick to the 24.lts.1+ branch label Jun 27, 2023
cobalt-github-releaser-bot pushed a commit that referenced this pull request Jun 27, 2023
The Chromium metrics libraries require any calls to their public APIs to
be invoked on the same thread in which they were created. Similarly,
H5vcc JS callback need to be invoked on the V8 thread.

This was being violated as the H5vcc callbacks were being invoked by a
non-V8 thread and H5vccMetrics was trying to call metrics APIs from a V8
thread.

The fix is to store the task runners for the
CobaltMetricsServicesManager and H5vccMetrics instances and use those to
run any tasks that must be run in the targeted thread.

This approach required a slight refactoring to allow the top level
CobaltMetricsServicesManager to provide its own public API to interact
with the underlying metrics client on a targeted thread.

I also found this approach allowed me to just pass around a
RepeatingCallback for the upload handler and remove the abstract class
that was being used before (CobaltH5vccMetricsUploaderCallback).

Added demo to verify everything is working.

b/288252273

Change-Id: I8243b27a1853c65ac9d4fe11adc95a7f4da9ed51
(cherry picked from commit a89e9fb)
joeltine added a commit that referenced this pull request Jun 27, 2023
…#737)

The Chromium metrics libraries require any calls to their public APIs to
be invoked on the same thread in which they were created. Similarly,
H5vcc JS callback need to be invoked on the V8 thread.

This was being violated as the H5vcc callbacks were being invoked by a
non-V8 thread and H5vccMetrics was trying to call metrics APIs from a V8
thread.

The fix is to store the task runners for the
CobaltMetricsServicesManager and H5vccMetrics instances and use those to
run any tasks that must be run in the targeted thread.

This approach required a slight refactoring to allow the top level
CobaltMetricsServicesManager to provide its own public API to interact
with the underlying metrics client on a targeted thread.

I also found this approach allowed me to just pass around a
RepeatingCallback for the upload handler and remove the abstract class
that was being used before (CobaltH5vccMetricsUploaderCallback).

Added demo to verify everything is working.

b/288252273

Change-Id: I8243b27a1853c65ac9d4fe11adc95a7f4da9ed51
(cherry picked from commit a89e9fb)

Co-authored-by: Joel Martinez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cp-24.lts.1+ Cherry Pick to the 24.lts.1+ branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants