dataconnect: DataConnectCredentialsTokenManager: initialize synchronously to fix race condition #6448
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the initialization of Data Conect's "Auth" and "AppCheck" mechanisms to be more synchronous. Not only does this fix a bug introduced a few commits ago by #6446 but also simplifies the logic and reduces the amount of non-determinism.
The race condition fixed by this PR manifested only on on my MacBook laptop (not on my Linux workstation) and is simply due to arbitrary thread scheduling differences. One such test failure looked like this:
The reason is that the DataConnectAuth object was used before its initialize() method was invoked. PR #6446 changed the logic to invoke initialize() in a separate coroutine, which introduced the race condition. By getting rid of the initialize() method altogether, and simply performing the initialization in an
init
block in DataConnectAuth (and DataConnectAppCheck) this race condition is completely eliminated.