subchannel list: fix ubsan error (#30393)

* don't expose vector type

* don't down-cast from inside base class ctor
pull/30346/head
Mark D. Roth 2 years ago committed by GitHub
parent 9511ab003a
commit 5ac68916df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  2. 1
      src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc
  3. 1
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  4. 22
      src/core/ext/filters/client_channel/lb_policy/subchannel_list.h

@ -229,6 +229,7 @@ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() {
}
latest_pending_subchannel_list_ = MakeOrphanable<PickFirstSubchannelList>(
this, std::move(addresses), latest_update_args_.args);
latest_pending_subchannel_list_->StartWatchingLocked();
// Empty update or no valid subchannels. Put the channel in
// TRANSIENT_FAILURE.
if (latest_pending_subchannel_list_->num_subchannels() == 0) {

@ -838,6 +838,7 @@ void RingHash::UpdateLocked(UpdateArgs args) {
}
latest_pending_subchannel_list_ = MakeOrphanable<RingHashSubchannelList>(
this, std::move(addresses), args.args);
latest_pending_subchannel_list_->StartWatchingLocked();
// If we have no existing list or the new list is empty, immediately
// promote the new list.
// Otherwise, do nothing; the new list will be promoted when the

@ -290,6 +290,7 @@ void RoundRobin::UpdateLocked(UpdateArgs args) {
}
latest_pending_subchannel_list_ = MakeOrphanable<RoundRobinSubchannelList>(
this, std::move(addresses), args.args);
latest_pending_subchannel_list_->StartWatchingLocked();
// If the new list is empty, immediately promote it to
// subchannel_list_ and report TRANSIENT_FAILURE.
if (latest_pending_subchannel_list_->num_subchannels() == 0) {

@ -178,9 +178,9 @@ class SubchannelData {
template <typename SubchannelListType, typename SubchannelDataType>
class SubchannelList : public InternallyRefCounted<SubchannelListType> {
public:
// We use ManualConstructor here to support SubchannelDataType classes
// that are not copyable.
using SubchannelVector = std::vector<ManualConstructor<SubchannelDataType>>;
// Starts watching the connectivity state of all subchannels.
// Must be called immediately after instantiation.
void StartWatchingLocked();
// The number of subchannels in the list.
size_t num_subchannels() const { return subchannels_.size(); }
@ -225,7 +225,9 @@ class SubchannelList : public InternallyRefCounted<SubchannelListType> {
const char* tracer_;
// The list of subchannels.
SubchannelVector subchannels_;
// We use ManualConstructor here to support SubchannelDataType classes
// that are not copyable.
std::vector<ManualConstructor<SubchannelDataType>> subchannels_;
// Is this list shutting down? This may be true due to the shutdown of the
// policy itself or because a newer update has arrived while this one hadn't
@ -395,10 +397,6 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
subchannels_.emplace_back();
subchannels_.back().Init(this, std::move(address), std::move(subchannel));
}
// Start watching subchannel connectivity state.
for (auto& sd : subchannels_) {
sd->StartConnectivityWatchLocked();
}
}
template <typename SubchannelListType, typename SubchannelDataType>
@ -412,6 +410,14 @@ SubchannelList<SubchannelListType, SubchannelDataType>::~SubchannelList() {
}
}
template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelList<SubchannelListType,
SubchannelDataType>::StartWatchingLocked() {
for (auto& sd : subchannels_) {
sd->StartConnectivityWatchLocked();
}
}
template <typename SubchannelListType, typename SubchannelDataType>
void SubchannelList<SubchannelListType, SubchannelDataType>::ShutdownLocked() {
if (GPR_UNLIKELY(tracer_ != nullptr)) {

Loading…
Cancel
Save