[C++] Make some clean up methods thread safe - #11762
Merged
merlimat merged 2 commits intoAug 25, 2021
Merged
Conversation
BewareMyPower
requested review from
aahmed-se,
jiazhai,
massakam,
merlimat and
sijie
August 24, 2021 14:43
Merged
1 task
merlimat
approved these changes
Aug 24, 2021
merlimat
reviewed
Aug 24, 2021
…ction pool is closed
merlimat
approved these changes
Aug 25, 2021
Member
|
Good work @BewareMyPower |
codelipenghui
pushed a commit
that referenced
this pull request
Sep 18, 2021
* Make some close methods thread safe * Restore shutdown() in ClientImpl's destructor and check whether connection pool is closed (cherry picked from commit 098ba16)
bharanic-dev
pushed a commit
to bharanic-dev/pulsar
that referenced
this pull request
Mar 18, 2022
* Make some close methods thread safe * Restore shutdown() in ClientImpl's destructor and check whether connection pool is closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #11760
Motivation
BasicEndToEndTest.testLookupThrottlingis flaky, from the logs of #11760 we can see the test crashed inClientImpl::shutdown. TheConnection closedlog shows thatConnectionPoolhas been closed, so the problem is related to the close of threeExecutorServiceProviders ofClientImpl.ExecutorServiceProvider::closeis not thread safe becauseExecutorServiceProvider::getmight access theexecutors_field in different threads andgetuses a lock to guarantee thread-safety whileclosedoesn't. In addition, some clean up methods includingClientImpl#shutdownandExecutorService#closemight be called twice or more, which is not necessary and has potential bugs.Modifications
The main changes are:
ExecutorServiceProvider::close.ExecutorService#closeis called only once.ConnectionPool#getConnectionAsyncbeing called afterclosemethod is closed. In this case, return a future that is completed withResultAlreadyClosed.In addition, this PR involves other changes. First, the master branch's source code cannot be compiled in my local env (macOS + Clang 12.0.0 + Boost 1.74), the error is:
I followed boostorg/proto#30 to fix this compilation error.
Another change is to fix the logs format, we can see the filename is always the same from logs in #11760. The reason is #11668 has changed
logger()method fromstatictoinline. It will make all C++'s translation units share the same and random chosen definition oflogger(), but we need different definitions with different__FILE__in different translation units. So this PR modifiedstaticback toinlineand fix related compilation errors.Verifying this change
This change is a trivial rework / code cleanup without any test coverage.