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

[C++] Delay ClientCredentialFlow::initialize to the first authenticate call #12372

Merged
merged 2 commits into from
Oct 15, 2021

Conversation

BewareMyPower
Copy link
Contributor

Fixes #12325

Motivation

C++ client uses one logger per thread, but if the logger of a thread has been initialized, even if the logger factory was changed, this logger would still keep not changed.

When a AuthOauth2 object is created, it calls ClientCredentialFlow::initialize, which calls LOG_DEBUG to try logging debug level logs. At this moment, the logger of the current thread is created and won't change after the custom logger factory is set in ClientImpl's constructor. Then the custom logger won't work for that thread.

Modifications

To avoid creating the logger in advance to ClientImpl's constructor, this PR delays ClientCredentialFlow::initialize to the first time ClientCredentialFlow::authenticate is called. Use std::call_once to ensure initialize is only called once.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

@BewareMyPower
Copy link
Contributor Author

Now all tests passed, PTAL again @merlimat

@merlimat merlimat merged commit d5e3ebb into apache:master Oct 15, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-set-logger branch October 15, 2021 16:51
hangc0276 pushed a commit that referenced this pull request Oct 17, 2021
…e call (#12372)

* Delay ClientCredentialFlow::initialize to the first time authenticate() is called

* Make once_flag object a field

(cherry picked from commit d5e3ebb)
@hangc0276 hangc0276 added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Oct 17, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…e call (apache#12372)

* Delay ClientCredentialFlow::initialize to the first time authenticate() is called

* Make once_flag object a field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C++] Custom logger doesn't work when OAuth 2.0 authentication is configured
3 participants