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

Bug 1779638 - Kotlin: Add a hook to run tasks after init #2116

Merged
merged 1 commit into from
Jul 18, 2022

Conversation

badboy
Copy link
Member

@badboy badboy commented Jul 15, 2022

We saw some intermittents on Android Components failing in the assert(isInitialized()) line.
This leads me to believe that it runs before Glean.initialize is
finished off-thread.
To fix this we introduce a new task queue: run things right after
Glean.initialize calls back into the wrapper.
We need to be careful though: This is triggered from the Rust side so we
can't call back and forth between Kotlin and Rust inside that task or we
risk deadlocks.
But in this instance we're safe:

  1. We only allow tasks in test mode
  2. We only call it in a single place

In theory there's a race condition still there, because we use
unsynchronized access to the afterInitQueue, but really ... it's test
mode and might just be fine enough for all we care? Let's hope so.

I am not able to reproduce the same error as in the intermittent locally
at all (neither in the simulator nor on an actual device), so really I
don't know if this "fixes" it.
The only way to test this out is to go through a release, get it into
A-C and then re-enable the tests and hope for the best.

We saw some intermittents on Android Components failing in the `assert(isInitialized())` line.
This leads me to believe that it runs before Glean.initialize is
finished off-thread.
To fix this we introduce a new task queue: run things right after
Glean.initialize calls back into the wrapper.
We need to be careful though: This is triggered from the Rust side so we
can't call back and forth between Kotlin and Rust inside that task or we
risk deadlocks.
But in this instance we're safe:
1. We only allow tasks in test mode
2. We only call it in a single place

In theory there's a race condition still there, because we use
unsynchronized access to the `afterInitQueue`, but really ... it's test
mode and might just be fine enough for all we care? Let's hope so.

I am not able to reproduce the same error as in the intermittent locally
at all (neither in the simulator nor on an actual device), so really I
don't know if this "fixes" it.
The only way to test this out is to go through a release, get it into
A-C and then re-enable the tests and hope for the best.
@badboy badboy requested a review from a team as a code owner July 15, 2022 13:34
@badboy badboy requested review from Dexterp37 and travis79 and removed request for a team and Dexterp37 July 15, 2022 13:34
Copy link
Member

@travis79 travis79 left a comment

Choose a reason for hiding this comment

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

Looks good to me, the only slight nit I might have is that seeing block() made me think that we were going to block and wait on something rather than what it is actually doing in executing a block of code. Just semantic really, not worth "blocking" on ;)

@badboy
Copy link
Member Author

badboy commented Jul 15, 2022

Looks good to me, the only slight nit I might have is that seeing block() made me think that we were going to block and wait on something rather than what it is actually doing in executing a block of code. Just semantic really, not worth "blocking" on ;)

heh, yeah, was thinking about "code block", maybe I should rename that variable to task or just func

@badboy
Copy link
Member Author

badboy commented Jul 18, 2022

Gonna land this so we get that to a-c. Still can't reproduce the initial error, but at the very least this doesn't make things worse.

@badboy badboy merged commit 2c37bd7 into main Jul 18, 2022
@badboy badboy deleted the after-init-hook branch July 18, 2022 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants