-
Notifications
You must be signed in to change notification settings - Fork 191
Fix[bmqio]: return peerUri by value to eliminate data race #1641
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,12 +95,13 @@ ResolvingChannelFactory_Channel::ResolvingChannelFactory_Channel( | |
| bslma::Allocator* basicAllocator) | ||
| : DecoratingChannelPartialImp(channel, basicAllocator) | ||
| , d_resolvedPeerUri(basicAllocator) | ||
| , d_basePeerUri(channel->peerUri(), basicAllocator) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. peerUri() returns a temporary now, so d_peerUri needs a stable copy to point at. d_basePeerUri owns that copy until resolution replaces it. |
||
| , d_peerUri() | ||
| { | ||
| // PRECONDITIONS | ||
| BSLS_ASSERT(channel); | ||
|
|
||
| d_peerUri = &channel->peerUri(); | ||
| d_peerUri = &d_basePeerUri; | ||
| } | ||
|
|
||
| // MANIPULATORS | ||
|
|
@@ -117,7 +118,7 @@ void ResolvingChannelFactory_Channel::updatePeerUri() | |
| } | ||
|
|
||
| // ACCESSORS | ||
| const bsl::string& ResolvingChannelFactory_Channel::peerUri() const | ||
| bsl::string ResolvingChannelFactory_Channel::peerUri() const | ||
| { | ||
| return *d_peerUri; | ||
| } | ||
|
|
@@ -235,7 +236,7 @@ void ResolvingChannelFactoryUtil::defaultResolutionFn( | |
| const ResolveFn& resolveFn, | ||
| bool verbose) | ||
| { | ||
| bslstl::StringRef peerUri = baseChannel.peerUri(); | ||
| bsl::string peerUri = baseChannel.peerUri(); | ||
| bslstl::StringRef colon = bdlb::StringRefUtil::strstr(peerUri, ":"); | ||
| if (colon.length() == 0) { | ||
| if (verbose) { | ||
|
|
@@ -248,7 +249,7 @@ void ResolvingChannelFactoryUtil::defaultResolutionFn( | |
|
|
||
| bdlma::LocalSequentialAllocator<128> arena; | ||
|
|
||
| bsl::string ipAddrStr(peerUri.data(), colon.data(), &arena); | ||
| bsl::string ipAddrStr(peerUri.c_str(), colon.data(), &arena); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bsl::string::data() returns char* in C++17, StringRef::data() returns const char*. Iterator pair deduction fails on the mismatch. c_str() is always const char*. |
||
| ntsa::IpAddress ipAddr; | ||
|
|
||
| if (!ipAddr.parse(ipAddrStr)) { | ||
|
|
@@ -277,7 +278,7 @@ void ResolvingChannelFactoryUtil::defaultResolutionFn( | |
| resolvedUri->append(ipAddrStr); | ||
| resolvedUri->append(1, '~'); | ||
| resolvedUri->append(resolvedName); | ||
| resolvedUri->append(colon.data(), peerUri.end()); | ||
| resolvedUri->append(colon.data(), peerUri.c_str() + peerUri.length()); | ||
| } | ||
|
|
||
| } // close package namespace | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ class Session : public SessionEventProcessor { | |
| /// executed. The execution result (structured, non-structured text or | ||
| /// possible error message) is expected to be passed to the specified | ||
| /// `onProcessed` callback. | ||
| typedef bsl::function<void(const bslstl::StringRef& source, | ||
| typedef bsl::function<void(const bsl::string& source, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StringRef bound into a thread pool job captures a pointer, not the data. With peerUri() returning a temporary, the data is freed before the job runs. |
||
| const bsl::string& command, | ||
| const AdminCommandProcessedCb& onProcessed, | ||
| bool fromReroute)> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.