Fix[bmqio]: return peerUri by value to eliminate data race - #1641
Merged
678098 merged 1 commit intoJul 27, 2026
Merged
Conversation
SrinathhSatuluri
force-pushed
the
fix/channel-peeruri-return-by-value
branch
from
July 24, 2026 20:29
2127fb6 to
176ee2c
Compare
| bslma::Allocator* basicAllocator) | ||
| : DecoratingChannelPartialImp(channel, basicAllocator) | ||
| , d_resolvedPeerUri(basicAllocator) | ||
| , d_basePeerUri(channel->peerUri(), basicAllocator) |
Contributor
Author
There was a problem hiding this comment.
peerUri() returns a temporary now, so d_peerUri needs a stable copy to point at. d_basePeerUri owns that copy until resolution replaces it.
SrinathhSatuluri
force-pushed
the
fix/channel-peeruri-return-by-value
branch
2 times, most recently
from
July 25, 2026 02:41
5beea8d to
301fb86
Compare
Signed-off-by: Srinath Satuluri <satulurisrinath@gmail.com>
SrinathhSatuluri
force-pushed
the
fix/channel-peeruri-return-by-value
branch
from
July 25, 2026 04:22
301fb86 to
d34e105
Compare
| 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.
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*.
| /// 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.
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.
Collaborator
|
Thank you for contribution @SrinathhSatuluri! |
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.
Closes #1611
Return peerUri by value instead of by const reference so the caller is not left holding an unprotected reference after the lock drops. This changes the base Channel interface and all four implementations. In ResolvingChannelFactory_Channel, the constructor previously took the address of the return value for the AtomicPointer pattern, so a stored copy is used instead. Also fixes two latent StringRef dangles that only worked because peerUri returned a reference to a stable member.
@678098