Skip to content

Commit

Permalink
core: RoundRobinLoadBalancer updates picker before shutting down subc…
Browse files Browse the repository at this point in the history
…hannels. (#5338)

This should lower the chance of the race between the pick and the
shutdown (#2562).
  • Loading branch information
zhangkun83 committed Feb 7, 2019
1 parent bcb11b1 commit 139e544
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/io/grpc/util/RoundRobinLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,19 @@ public void handleResolvedAddressGroups(
subchannel.requestConnection();
}

// Shutdown subchannels for removed addresses.
ArrayList<Subchannel> removedSubchannels = new ArrayList<>();
for (EquivalentAddressGroup addressGroup : removedAddrs) {
Subchannel subchannel = subchannels.remove(addressGroup);
shutdownSubchannel(subchannel);
removedSubchannels.add(subchannels.remove(addressGroup));
}

// Update the picker before shutting down the subchannels, to reduce the chance of the race
// between picking a subchannel and shutting it down.
updateBalancingState();

// Shutdown removed subchannels
for (Subchannel removedSubchannel : removedSubchannels) {
shutdownSubchannel(removedSubchannel);
}
}

@Override
Expand Down

0 comments on commit 139e544

Please sign in to comment.