Skip to content

Fix[bmqio]: return peerUri by value to eliminate data race - #1641

Merged
678098 merged 1 commit into
bloomberg:mainfrom
SrinathhSatuluri:fix/channel-peeruri-return-by-value
Jul 27, 2026
Merged

Fix[bmqio]: return peerUri by value to eliminate data race#1641
678098 merged 1 commit into
bloomberg:mainfrom
SrinathhSatuluri:fix/channel-peeruri-return-by-value

Conversation

@SrinathhSatuluri

Copy link
Copy Markdown
Contributor

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

@SrinathhSatuluri
SrinathhSatuluri requested a review from a team as a code owner July 24, 2026 20:24
@SrinathhSatuluri
SrinathhSatuluri force-pushed the fix/channel-peeruri-return-by-value branch from 2127fb6 to 176ee2c Compare July 24, 2026 20:29
bslma::Allocator* basicAllocator)
: DecoratingChannelPartialImp(channel, basicAllocator)
, d_resolvedPeerUri(basicAllocator)
, d_basePeerUri(channel->peerUri(), basicAllocator)

@SrinathhSatuluri SrinathhSatuluri Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

@SrinathhSatuluri
SrinathhSatuluri force-pushed the fix/channel-peeruri-return-by-value branch 2 times, most recently from 5beea8d to 301fb86 Compare July 25, 2026 02:41
Signed-off-by: Srinath Satuluri <satulurisrinath@gmail.com>
@SrinathhSatuluri
SrinathhSatuluri force-pushed the fix/channel-peeruri-return-by-value branch from 301fb86 to d34e105 Compare July 25, 2026 04:22
Comment thread src/groups/bmq/bmqio/bmqio_ntcchannel.cpp
bdlma::LocalSequentialAllocator<128> arena;

bsl::string ipAddrStr(peerUri.data(), colon.data(), &arena);
bsl::string ipAddrStr(peerUri.c_str(), colon.data(), &arena);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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*.

/// 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,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

@678098 678098 self-assigned this Jul 26, 2026

@678098 678098 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@678098
678098 merged commit fb2004a into bloomberg:main Jul 27, 2026
53 checks passed
@678098

678098 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Thank you for contribution @SrinathhSatuluri!

@SrinathhSatuluri
SrinathhSatuluri deleted the fix/channel-peeruri-return-by-value branch July 27, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix[bmqio]: data races on d_streamSocket_sp and d_peerUri in NtcChannel

2 participants